Examples of externally managing dependency versions, anyone?


(Doug Lethin) #1

The gradle users guide in section 50.8.2.2 (Implement a custom versioning scheme) provides an example of registering a resolutionStrategy that relies on custom logic to lookup the version to use. Code looks like this:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.version == 'default') {
            def version = findDefaultVersionInCatalog(details.requested.group, details.requested.name)
            details.useVersion version
        }
    }
}
  def findDefaultVersionInCatalog(String group, String name) {
    //some custom logic that resolves the default version into a specific version
    "1.0"
}

This sounds very useful. Ideally I would love to centrally manage this. For example, in our maven builds today, each time we publish a new version of a library and want all of our consuming apps to use it, for each app we need to modify the pom file and point to the new version.

There is a maven versions plug which might make this easier, but it doesn’t change the fact that this information needs to be maintained.

I’m just curious if any one on the forum can share any experiences with using this technique. How did you implement it. Is it working for you? Are there any gotchas/edge cases?

Thanks.

Doug