Adding dependencies programatically WITH a specific dependency configuration


(Andi) #1

Adding dependencies programmatically WITHOUT dependency configuration is easy (example here or below):
project.dependencies.add("myConfig", "myGroup:myName:myVersion")

But how can I add a dependency WITH a specific configuration? For example:
dependencies { myConfig (group: "myGroup", name: "myName", version: "myVersion", configuration: "myDependencyConfiguration") }

Having a look at the DependencyHandler a closure can be used to configure the dependency, but it seems the configuration property is read-only.
project.dependencies.add(myConfig, "myGroup:myName:myVersion", { configuration = "myDependencyConfiguration" })

This results in Cannot set the value of read-only property 'configuration' on DefaultExternalModuleDependency

I also tried this, but it does not work:
project.dependencies.add(myConfig, group: "myGroup", name: "myName", version: "myVersion", configuration: "myDependencyConfiguration")

How can I create a dependencyNotation object that works for my case?


"Unable to resolve class" when compiling Jenkins Groovy script
(Andi) #2

Finally found the solution. The dependencyNotation object needs to be a map:

project.dependencies.add(configurationKey, [group: "myGroup", name: "myName", version: "myVersion", configuration: "myDependencyConfiguration"])