Force version alignment for a group of libraries

Hi

Our organization published a set of libraries which are consumed by a multi-project and by each other.

When resolving the dependency graph we would like gradle to align all module of same library to the highest version it find for that same library.

So for example:
If in our multi-project we declare a dependency on:
lib A Module x and z version 1 and on lib B Module y version 2
lib B module y version 2 depends on lib A Module x version 2

So gradle will fetch lib-A module-x version-2 lib-A module-z version-1 lib-B module-y version-2
But we would like to align all module of lib A to highest version found: 2 (found for module x)

We do not know ahead the version each library needs, that info can be fetch from all transitive dependency, but that can be found only after gradle resolved all dependency, and so it is too late.

Any suggestion ? Solutions?

Thanks
Jonathan

The solution here could be adapted to find all versions for a particular groupId and force the latest for the whole group

Hi Lance , thanks for the response

However i think that the suggested solution can’t work.

When iterating into eachDependency clouser, we can detect the higher version of a module and then set the useVersion later on under the Strategy, but we do not have the complete graph cause maybe the new version depends on other module with higher version we did not detect under eachDependency clouse.

For example let say we found for lbrary A moulde x version 1 and module y version 2 so we upgrade x to version 2 but when we do that x can bring more dependencies we did not iterate under eachDependency clouser.

We need somehow ask Gradle to calculate the graph and for each library found collect its modules and set to the highest version found. Then recalculate again and again till it converge. Mathematically speaking i think we can prove that it must converge (with detecting cycle) .

Thanks
Jonathan