Hello,
as part of a task I would like copy a resolved configuration (in the example below ‘compile’), add some additional dependencies and resove the copy. It is important for my use case to add additional dependencies in between of resolving the configuration. The code snippet below defines the configuration ‘compile’ with the dependency ‘spring-jdbc’ and the copied configuration adds the dependency ‘spring-ws-core’. But ‘spring-ws-core’ will be not added to the resolved artifacts. The number of the resolved artifacts is in both cases 7.
repositories {
mavenCentral()
}
configurations {
compile {
transitive = true
}
}
dependencies {
compile (group: 'org.springframework', name: 'spring-jdbc', version: '2.5.6')
}
task myTask << {
def compileConf = project.configurations.getByName('compile')
println "State of configuration 'compile': " + compileConf.state //UNRESOLVED is expected
println "Resolve configuration and print count of resolved artifacts: " + compileConf.resolvedConfiguration.resolvedArtifacts.size()
println "State of configuration 'compile': " + compileConf.state //RESOLVED is expected
def compileCopyConf = compileConf.copy()
println "State of configuration 'compileCopy': " + compileCopyConf.state //UNRESOLVED is expected
println "compileCopyConf.size: " + compileCopyConf.dependencies.size()
compileCopyConf.dependencies.add(['org.springframework.ws:spring-ws-core:2.2.0.RELEASE'])
println "State of configuration 'compileCopy': " + compileCopyConf.state //UNRESOLVED is expected
println "compileCopyConf.size: " + compileCopyConf.dependencies.size()
println "Resolve configuration and print count of resolved artifacts: " + compileCopyConf.resolvedConfiguration.resolvedArtifacts.size()
println "State of configuration 'compileCopy': " + compileCopyConf.state //RESOLVED is expected
}
Output:
Executing command: ":myTask"
:myTask
State of configuration 'compile': UNRESOLVED
Resolve configuration and print count of resolved artifacts: 7
State of configuration 'compile': RESOLVED
State of configuration 'compileCopy': UNRESOLVED
compileCopyConf.size: 1
State of configuration 'compileCopy': UNRESOLVED
compileCopyConf.size: 2
Resolve configuration and print count of resolved artifacts: 7
State of configuration 'compileCopy': RESOLVED
BUILD SUCCESSFUL
Total time: 12.167 secs
Completed Successfully
Can somebody advice? Kinde Regards Markus