palantir / gradle-consistent-versions

Compact, constraint-friendly lockfiles for your dependencies
Apache License 2.0
116 stars 14 forks source link

migrating to gradle-consistent-versions breaks dependencySubstitution #39

Open iamdanfox opened 5 years ago

iamdanfox commented 5 years ago

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.

dansanduleac commented 5 years ago

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...