Question

I followed the advice in this Gradle forum entry because I was getting corrupted images in my Gradle-generated WAR file due to Ant style token replacement. However, I can't get the token replacement to work properly. Here's a snippet of the WAR configuration:

from project(':module0').fileTree('resource')
webInf {
  from gradleProject.project(':module1').fileTree(dir: 'config/props/skel',
    includes: ['*.properties', '*.xml'], excludes: ['blah1.properties', 'blah2.properties'])
    filesMatching('classes/props/*.properties'){
      filter(ReplaceTokens, tokens: props)
    }
    filesMatching('classes/props/*.xml'){
      filter(ReplaceTokens, tokens: props)
    }
}.into('classes/props/')//.filter(ReplaceTokens, tokens: props)

from(gradleProject.project(':module2').file('resource/version.txt'))//.filter(ReplaceTokens, tokens: props)
filesMatching('version.txt'){
  filter(ReplaceTokens, tokens: props)
}

//filesMatching('WEB-INF/classes/props/*.properties'){
//  filter(ReplaceTokens, tokens: props)
//}
//filesMatching('WEB-INF/classes/props/*.xml'){
//  filter(ReplaceTokens, tokens: props)
//}

//filesMatching('WEB-INF/classes/props/*'){
//  filter(ReplaceTokens, tokens: props)
//}

The code above only works for the version.txt file. All the files in WEB-INF/classes/props don't get filtered at all. The commented call to filter works but somehow it ends up breaking images that get copied from the module0/resource folder (really odd). Finally the last two commented blocks of code don't work either.

What is the correct way of doing this?

Était-ce utile?

La solution

OK this is dumb. Apparently I got really close:

from project(':module0').fileTree('resource')
webInf {
  from gradleProject.project(':module1').fileTree(dir: 'config/props/skel',
    includes: ['*.properties', '*.xml'], excludes: ['blah1.properties', 'blah2.properties'])
    filesMatching('WEB-INF/classes/props/*'){
      filter(ReplaceTokens, tokens: props)
    }
}.into('classes/props/')//.filter(ReplaceTokens, tokens: props)

seems to work fine.

Autres conseils

You need to use:

filesMatching('WEB-INF/classes/props/*'){
  filter(ReplaceTokens, tokens: props)
}

See: http://forums.gradle.org/gradle/topics/filesmatching_in_a_copyspec_does_not_work

The resource directory is processed by 'processResources' thus the annoyance of trying to force it into webInf (which I agree seems like a reasonable place given these files end up in WEB-INF). But I think what you want (outside your war{} block):

    processResources {
        filesMatching('classes/props/*'){
            filter(ReplaceTokens, tokens: props)
        }
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top