This is sort of an extension of what I was running into in Configuration and transitive dependency management by extension . I was trying an approach that uses beforeResolve
instead and copies the correct dependencies around into other configurations, but my tests were failing and I was confused as to why.
Should configurations that are extended from be resolved when a configuration extending it is resolved? My expectation was “yes”, but the docs don’t say what should happen, or even what extendsFrom
means. This was surprising to me.
Here is a short example:
wrapper.gradleVersion = '4.2.1'
configurations {
mkparent
mk.extendsFrom(mkparent)
}
repositories {
jcenter()
}
dependencies {
mkparent group: 'junit', name: 'junit', version: '4.12'
mk group: 'com.google.guava', name: 'guava', version: '23.0'
}
configurations.mkparent.incoming.beforeResolve {
println('mkparent: BEFORE RESOLVE')
}
configurations.mk.incoming.beforeResolve { resolvableDependencies ->
println 'mk: BEFORE RESOLVE'
}
tasks.create("show") {
group = 'TESTING'
doFirst {
final mk = configurations.mk
[
mk
].each {
println("Configuration: ${it.name}")
it.resolvedConfiguration.firstLevelModuleDependencies.each {
println(" First level: $it")
}
println()
it.resolvedConfiguration.resolvedArtifacts.each {
println(" Resolved: $it")
}
println()
println('-' * 100)
println()
}
println("mkparent State=${configurations.mkparent.state}")
println("mk State=${configurations.mk.state}")
}
}
And the output shows that mkparent
is not resolved:
Configuration: mk
mk: BEFORE RESOLVE
First level: com.google.guava:guava:23.0;default
First level: junit:junit:4.12;default
Resolved: guava.jar (com.google.guava:guava:23.0)
Resolved: junit.jar (junit:junit:4.12)
Resolved: jsr305.jar (com.google.code.findbugs:jsr305:1.3.9)
Resolved: error_prone_annotations.jar (com.google.errorprone:error_prone_annotations:2.0.18)
Resolved: j2objc-annotations.jar (com.google.j2objc:j2objc-annotations:1.1)
Resolved: animal-sniffer-annotations.jar (org.codehaus.mojo:animal-sniffer-annotations:1.14)
Resolved: hamcrest-core.jar (org.hamcrest:hamcrest-core:1.3)
----------------------------------------------------------------------------------------------------
mkparent State=UNRESOLVED
mk State=RESOLVED