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?
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.
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.