How to exclude files from src/main/resources when create WAR archive?

I have read many topics which are similar with my problem, but they all do not meet my requirements.

I have two config file for different deployment environment, and they are placed in other two folders.[overlays/test/config.properties / overlays/prod/config.properties]

I have another config file in folder [src/main/resources/config.propertis] for IDE integration test use.

I want create war archive files for different environment, so I create two tasks to create these files, but i got duplicated config file under the same folder in war archive [WEB-INF/classes],

so my problem is : i want exclude the config file “config.properties” from the folder “src/main/resources/” when i create the war archive, then there will be only one config.properties file under the folder “WEB-INF/classes” per war archive.

the task i created like below:

  task assemblyTest (type: War, dependsOn: classes) {

baseName = project.name+’-test’

from("./overlays/test") {

into(“WEB-INF/classes”)

include “**/*”

} }

task assemblyProd(type: War, dependsOn: classes) {

baseName = project.name+’-prod’

from(’./overlays/prod/resources’) {

into(“WEB-INF/classes”)

include “**/*”

duplicatesStrategy = DuplicatesStrategy.FAIL

} }

thanks for your help very much!

I found another solution

1.create another folder “overlays/dev” 2.move all the files from “src/main/resources” to “overlays/dev” 3.defined a new task to copy the files under folder “overlays/dev” to “build/resources” when run the jettyRun task.

  task copyDevOverlays (type:Copy) {



into("build/resources/main")



from ("overlays/dev") {





 include "**/*"



}  }  jettyRun.dependsOn copyDevOverlays  

Hey Robin,

if the purpose of your config file at src/main/resources/config.properties, the best way to filter it out might be to do that in the processResources task instead of the war

processResources{
    exclude 'config.properties'
}

Alternativley you can put that config file in a dedicated folder (src/eclipseonly/config.properties) and tweak the eclipseClasspath task to take that folder into account when generating the eclipse environment.

cheers, René

Rene, thanks for your reply.

if i exclude the config.properties in the processResources phase, the jettyRun task will failed, because this file can not be found in the classpath.

and i’m a user of Intellij Idea, is there any dedicated folder for Intellij Idea as eclipse?

the dedicated folder I mentioned before isn’t build-in in eclipse. it was just a suggestion. You can do the same thing for idea. and configure the idea setup to pickup that folder:

idea {
    module {
    sourceDirs += file('some-extra-source-folder')
  }
}

but since you need that file when running jettyRun this does not solve your problems. I thought you just need the config file in src/main/resources in intellij

Rene, i really appreciate your reply.

i solved my problem use the way what i shared in the first reply.