I need some help on the basics of dependency subst...
# dependency-management
k
I need some help on the basics of dependency substitution. Currently, I have a project that does this:
Copy code
configurations.all {
  resolutionStrategy.dependencySubstitution {
    substitute(module("foo:bar")).using(module("foo:baz:1.0"))
  }
}
How is this different from
Copy code
dependencies {
  modules {
    module("foo:bar") {
      replacedBy("foo:baz")
    }
  }
}
and which one is preferred?
j
You likely want the first. The second, a module replacement rule, only kicks in when both bar and baz appear in the graph. In that case, conflict occurs and baz will win. With a substitution, the rule always applies. Whenever the graph sees a dependency for bar it treats it as a dependency for baz
k
Is the specific version necessary?
j
I believe so. Not completely sure
If you want to be more dynamic you can use component metadata rules to rewrite the incorrect dependency’s metadata to use the module you want, taking into account the version