What I am trying to achieve: We develop a web application that depends on number of our own and third party libraries. We want to exclude some of these third party libraries from the WAR file built by Gradle. We have grouped such third party libraries using a configuration called “noDist”.
In the root build file:
allprojects {
configurations {
noDist {
description = 'Compile classpath for libraries that are NOT DISTRIBUTED to customers.'
}
compile.extendsFrom noDist
}
dependencies {
noDist(group:'net.sourceforge.findbugs', name:'annotations', version:'1.3.2')
testCompile(group:'junit', name:'junit', version:'4.10')
}
}
In the libA build file:
dependencies {
noDist(group: '', name: 'nonDistributableLibX', version: '')
}
In the web app build file:
dependencies {
compile(project(':libA'))
noDist(name: 'nonDistributableLibY')
providedCompile(group: 'javax.servlet', name: 'servlet-api', version:'2.4')
}
war {
classpath -= configurations.noDeployNoDist
}
The library “nonDistributableLibY.jar” is correctly excluded from the Gradle built WAR file but the library “nonDistributableLibX.jar” is included.
This is because, I assume that “configurations.noDeployNoDist” inside the WAR closure only contains dependencies declared in this project but, none from the dependent projects.
Currently I have work-around, but wondering what is the correct / elegant way to exclude transient dependencies based on configuration from a WAR file (if that is possible).
Thanks