Filtering files added to WEB-INF

I’m trying to filter out and rename some files from the classpath when creating a war:

war {

from “${project(’:frontend’).projectDir}/app”

filesMatching(’**/*’) {

println “main filesMatching: $it”


webInf {

filesMatching(’**/*’) {

println “webInf filesMatching: $it”




I see all the files coming from the ‘…/frontend/app’ directory being printed as expected, from both filesMatching blocks, but none of the files coming from the classpath is being printed. So I haven’t found any way to remove (or rename) some files, coming from the classpath, from the war.

Is that expected? How can I filter files from the classpath?

BTW, another thing that surprises me is that the ‘webInf.fileMatching’ block prints files that don’t go into WEB-INF.

If you are trying to prevent classpath items from being included in the WAR you can use the ‘’‘providedCompile’’’ configuration.

No, that’s not what I’m trying to do. I’m trying to exclude and rename some files coming from the resources. I need them in build/resources/main when executing my unit tests, but I don’t want them in the war.


from ("${project(':frontend').projectDir}/app") {
    rename ....
    exclude ...

Nope. that would allow renaming and excluding files coming from the ‘…/frontend/app’ folder.

What I want is to rename and exclude files coming from the current project’s ‘build/resources/main’ folder and going to the ‘WEB-INF/classes’ directory of the war. These are copied implicitely by the war task.

I got it working with ‘war.rootSpec.filesMatching(“WEB-INF/classes/**”) { println it.path }’, but it shouldn’t have to be that hard. Raised GRADLE-3151 to investigate.

Thank you Peter. Great.