Detecting Incompatible Dependencies in Maven?

Suppose you have a set of web applications that use different versions of a shared library, such as Spring. I have a business logic library that also uses this shared library. Not a problem yet, but along the way, the shared library version changed the definition of an abstract class and broke the business logic library.

So, I get a compatible version of a table that looks like this:

business-lib-version | common-lib-version 1.0 | 1.0 1.1 | 2.0 

I do not want the version of the business library to manage the general version of lib in the consumer application. Rather, I would like to choose the right version of the business library based on the shared library. I am pretty sure that this is not possible, so I turn to the main question.

Is there an elegant way to detect version incompatibility? Ideally, I would like to use a build-time solution, otherwise an early runtime would be fine.

I tried using version ranges in Maven, but it caused us a lot of problems due to the way Maven sorts versions in non-standard formats, and we also had various problems when changing ranges correctly during build.

+6
source share
2 answers

Ning dependency-versions-check The Maven plugin will not be able to build if the version of the dependencies is accidentally constrained by another dependency. It will not help you, but it will at least tell you!

+4
source

I don’t know how to do this - either at runtime or even at build time. There is no standard mechanism for determining package versions without examining manifests or jar file names, which would be a hack at best. Maybe there is a maven plugin that I don't know about, it does this automatically, but I don't know about that.

We simply fix the versions of the libraries that we need for our code, and update when we need it either because we need additional functions or another dependency. Usually we are ahead of other dependencies, so we put a typical exception marker in our dependency definitions in pom.xml :

 <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>${spring-version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> 

This allows us to depend on a later version of commons-logging .

If, however, you use 1.0 libraries, but one of your dependencies uses 2.0, then you will have to try exclusion and see if the dependency works with 1.0 or even compilers. If not, you will either have to update the code to work with 2.0, or reduce the dependency.

Sorry I can’t help.

0
source

Source: https://habr.com/ru/post/909749/


All Articles