Assume you have set of web apps that use various versions of a common library like Spring. I have a business logic library that also uses this common library. So far no problem, but along the way a version of the common library changed an abstract class definition and broke the business logic library.
So I end up with a compatible version table that looks like this...
business-lib-version | common-lib-version
1.0 | 1.0
1.1 | 2.0
I don't want the business lib version to drive the common lib version in the consuming application. Rather I would like to pick the correct version of the business lib based on the common lib. I'm pretty sure that's not possible so I move on to the main question.
Is there an elegant way to detect version incompatibilities? Ideally I would like a build time solution, otherwise an early run-time solution would be ok.
I've tried using version ranges in Maven but this has caused us many problems due to how Maven sorts versions in non-standard version formats and we also had various issues in resolving ranges correctly at build time.
One way to resolve a version collision is by removing a conflicting transitive dependency from specific artifacts. In our example, we don't want to have the com. google. guava library transitively added from the project-a artifact.
Each maven dependency defined in the pom must have a version either directly or indirectly for example, through dependencyManagement or parent. That being said, if the version is not given, then the version provided in the dependencyManagement or the parent pom will be used.
We can use mvn dependency:tree -Dverbose command to print the dependency conflicts. It can help us in determining if there are any incompatibility issues with a JAR.
Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.
The Ning dependency-versions-check Maven plugin will fail your build if a dependency version has accidentally been held back by another dependency. It won't fix it for you, but it'll at least tell you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With