Prefer remote dependency over linked project

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


   includeBuild ../ProjectB

   dependencies {


OtherProject (not included in ProjectA)

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
                    && == ""
            ) {
                def snapshotVersion = "${requestedDependency.version}-SNAPSHOT"
                def target = "${}:${requestedDependency.module}:$snapshotVersion"

The issue is

  1. when I resolve b-module dependency, it always returns the project
  2. The requested dependency doesn’t include the -SNAPSHOT suffix.
publishing {
    publications {
        withType(MavenPublication.class).configureEach {
            versionMapping {
                usage(Usage.JAVA_RUNTIME) {

                    def resolved = it.maybeResolveVersion("", "b-module", "0.0.1-SNAPSHOT")
                    println("Resolved: $resolved")

                   ResolutionResult resolutionResult = it.targetConfiguration

                    resolutionResult.getAllDependencies().forEach { dependencyResult ->
                        if (dependencyResult.getRequested().getGroup() == "") {
                            println("Dependency is '${dependencyResult.getRequested()}'")

// Resolved: project :project-b:b-module
// Dependency is '`

Any hint will be greatly appreciated :pray:

If I remove the includeBuild, my setup to publish snapshots works fine.

I didn’t read the full post, but the link you ask for in the beginning is most probably ResolutionStrategy#getUseGlobalDependencySubstitutionRules which you then would set to false. Maybe that helps you resolve your problem. :slight_smile:


That did the trick :heart_eyes:

I think it’s the 3rd time you save my day on this forum, so huge thanks to you :bowing_man:

1 Like