I want to configure dependency resolution so that it prefers remote version over linked project
From Gradle picks wrong jars in multi-module project with diamond dependencies - #2 by Schalk_Cronje
If the dependency is found in a linked project it will be preferred over the remote version (unless you have configured it not to).
It doesn’t link to documentation backing the statement, nor it explains how to configure dependency resolution to prefer remote over linked project.
My setup looks as follows
group=my.group
version=0.0.1
ProjectB
b-module
ProjectA
includeBuild ../ProjectB
dependencies {
api("my.group:b-module:version")
api("my.group:other-module:version")
}
OtherProject (not included in ProjectA)
other-module
When releasing, I first publish ProjectB & OtherProject to maven, followed by ProjectA. This works fine.
The thing is, now I want to publish snapshot versions. Because it’s a complex project with multiple includeBuild, I can’t append -SNAPSHOT
to every internal dependency, and I’m trying to apply dependency substitution rules
configurations.configureEach {
resolutionStrategy.dependencySubstitution { dependencySubstitutions ->
all { dependency ->
def requestedDependency = dependency.requested
if (requestedDependency instanceof ModuleComponentSelector
&& requestedDependency.group == "my.group"
) {
def snapshotVersion = "${requestedDependency.version}-SNAPSHOT"
def target = "${requestedDependency.group}:${requestedDependency.module}:$snapshotVersion"
dependency.useTarget(target)
}
}
}
}
The issue is
- when I resolve
b-module
dependency, it always returns the project - The requested dependency doesn’t include the
-SNAPSHOT
suffix.
publishing {
publications {
withType(MavenPublication.class).configureEach {
versionMapping {
...
usage(Usage.JAVA_RUNTIME) {
fromResolutionOf("releaseRuntimeClasspath")
def resolved = it.maybeResolveVersion("my.group", "b-module", "0.0.1-SNAPSHOT")
println("Resolved: $resolved")
ResolutionResult resolutionResult = it.targetConfiguration
.getIncoming()
.getResolutionResult();
resolutionResult.getAllDependencies().forEach { dependencyResult ->
if (dependencyResult.getRequested().getGroup() == "my.group") {
println("Dependency is '${dependencyResult.getRequested()}'")
}
}
}
}
}
}
// Resolved: project :project-b:b-module
// Dependency is 'my.group:b-module:0.0.1`
Any hint will be greatly appreciated