Replacing a development dependency with a deployment dependency while reusing the configuration for java webstart

How do I swap out one dependency in my custom configuration that extends the runtime or compile configuration?

One of the dependencies I use in my project has 2 versions: a development version for use while developing and a deployment version for use when deploying our product to users. This dependency is commercial software, so they do this for licensing reasons and the two versions (jars) contain the same classes but a different way of handling licensing.

In order to reuse my dependency configuration, I would like to extend the runtime configuration with a custom configuration called “deployment”. The deployment configuration should use all the same jars as runtime, but swap out this one dependency with the deployment version. The jars will then be signed and packaged for Java webstart.

Currently, I have the following code. I have the sense that there is a better way to do this in Gradle. Is there?

configurations {
  dependencies {
 def runtimeDependencies = fileTree(dir: 'lib', include: '*.jar')
    def deploymentDependencies = runtimeDependencies -
        fileTree(dir: 'lib', include: "tsallperspectives40dev.jar") +
     fileTree(dir: 'lib', include: "tsallperspectives40dep.jar")
    runtime runtimeDependencies
 deployment deploymentDependencies

./gradlew -v

------------------------------------------------------------ Gradle 1.8 ------------------------------------------------------------

Build time:

2013-09-24 07:32:33 UTC Build number: none Revision:



1.8.6 Ant:

Apache Ant™ version 1.9.2 compiled on July 8 2013 Ivy:

2.2.0 JVM:

1.7.0_10 (Oracle Corporation 23.6-b04) OS:

Mac OS X 10.8.5 x86_64

This is a bit tricky because you are using anonymous dependencies. There’s no real way to talk about replacing one dependency with another because there’s no way to identify them.

Is this still an issue for you?

Yeah, it’s still an issue, but it’s a low priority. The build system is working great!

What I wanted out of this question was to understand “The Gradle Way” to do this. Is the Gradle way to use named dependencies? Instead of anonymous? What would that look like?

There’s actually only one dependency that I need to swap out. The code in the original post creates two file collections with a single file each. One with the deployment jar and one with the development jar. Then, set union and subtraction are performed to swap out the dependency.

This has worked fine so far, but down the road I’m concerned this will have a snowball effect on the complexity of the build system if it’s not adhering to good practices.

I’m not sure how much know about Gradle’s dependency management, so it’s hard to say.

Definitely have a read of this:

Note that dependencies have to be external, you can use flatFile repositories:

My latest iteration of this thread is

configurations {



dependencies {

runtime fileTree(dir: ‘lib’, include: ‘*.jar’)

deployment configurations.runtime -

fileTree(dir: ‘lib’, include: “tsallperspectives40dev.jar”) +

fileTree(dir: ‘lib’, include: “tsallperspectives40dep.jar”)


For the record or any readers that may have a similar situation.