A user of our plugin has reported a problem when their build contains projects with cyclic dependencies. I’ve reduced this down to a short example that removes the plugin from the picture.
When a build contains circular dependencies between two of its projects, a recursive copy of a configuration that itself resolves successfully will fail to resolve if the copy is made in beforeResolve
or afterResolve
. This is illustrated in the following build.gradle
:
subprojects {
apply plugin: 'java'
}
project (':alpha') {
dependencies {
testCompile project(':bravo')
}
configurations.testRuntime.incoming.beforeResolve {
configurations.testRuntime.copyRecursive().resolve()
}
}
project (':bravo') {
dependencies {
compile project(':alpha')
}
}
It will fail when running alpha:dependencies
:
Execution failed for task ':alpha:dependencies'.
> Could not resolve all dependencies for configuration ':alpha:testRuntimeCopy'.
> Module version gh-46:bravo:unspecified, configuration 'default' declares a dependency on configuration 'default' which is not declared in the module descriptor for gh-46:alpha:unspecified
As mentioned above, the failure only occurs when the copy is made during resolution, i.e. within beforeResolve
or afterResolve
. The copy will resolve successfully if it is made either before or after the original configuration is resolved:
configurations.testRuntime.copyRecursive().resolve()
configurations.testRuntime.resolve()
configurations.testRuntime.copyRecursve().resolve()