Is it possible to exclude transitive dependencies of a project using custom configuration?

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

When you take a project dependency, you are depending on a configuration in the other project named ‘default’. When using the Java plugins, this guy ends up extending the ‘runtime’ configuration. The simplest solution will be to change the inheritance setup of this configuration so that it doesn’t include the things you don’t want to export. This is just a matter of getting the setup of the configurations right in terms of extendsFrom etc.