gradle-consistent-versions icon indicating copy to clipboard operation
gradle-consistent-versions copied to clipboard

migrating to gradle-consistent-versions breaks dependencySubstitution

Open iamdanfox opened this issue 6 years ago • 1 comments

What happened?

In a repo using nebula dependency recommender, we used the following snippet to make com.palantir.baseline-class-uniqueness pass:

    configurations.all {
        resolutionStrategy {
            dependencySubstitution {
                substitute module('org.glassfish.hk2.external:javax.inject') with module('javax.inject:javax.inject:1')
            }
        }
    }

After switching to gradle-consistent-versions, I hit this:

$ ./gradlew --write-locks

* What went wrong:
A problem occurred configuring root project 'witchcraft'.
> Could not find method module() for arguments [org.glassfish.hk2.external:javax.inject] on object of type org.gradle.api.internal.artifacts.ivyservice.resolutionstrategy.DefaultResolutionStrategy.

Then fiddling with closures:

    configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute module('org.glassfish.hk2.external:javax.inject') with module('javax.inject:javax.inject:1')
        }
    }
$ ./gradlew --write-locks

* What went wrong:
A problem occurred configuring root project 'witchcraft'.
> Could not find method module() for arguments [org.glassfish.hk2.external:javax.inject] on configuration ':witchcraft-benchmarks:subprojectUnifiedClasspathCopy' of type org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.

What did you want to happen?

Either this syntax should be magically work fine (and not barf on the subprojectUnifiedClasspathCopy), or we should provide a clear recommendation for how to achieve these workflows.

iamdanfox avatar Mar 05 '19 15:03 iamdanfox

It looks like dependencySubstitution takes an Action<DependencySubstitutions>, not a Closure, and module is a method on that DependencySubstitutions. Not sure how or when groovy decides to implicitly look up things in the only argument of a functional interface. The error messages seem to suggest that the innermost closure isn't looking at that method's parameter (the DependencySubstitutions) when trying to decide where module(String) comes from...

dansanduleac avatar Mar 05 '19 16:03 dansanduleac