Maven How to break backward compatibility?

Maven has a version control system that selects the highest version of the library if multiple versions are referenced. For example, if pom A is version 1.1 and pom B is 1.2, then pom C (referring to both A and B) will use the highest version; 1.2.

This approach assumes that 1.2 is 100% backward compatible with 1.1, and this is a good and required approach. However, at certain times in the life cycle of libraries it is wise to empty the store. For me, any major changes to the API mean an increase in the main version, so 2.0 should not be 100% backward compatible with the latest 1.x. Good.

Maven, however, doesn’t care, and if pom B is upgraded from 1.2 to 2.0, Maven will use 2.0, but pom A cannot work with this version.

How to tell Maven that the version is no longer compatible with the previous version?

I tried to specify exclusion ranges, so A refers to [1.1.1.999] and B refers to [2.0.2.999]. However, Maven still solves the maximum version number (2.0).

+4
source share
3 answers

It's a bad practice to use version ranges in Maven Builds at first, and you also need to define a version numbering definition that says 1.0 and 1.1 should be back, whereas 2.0 is not the definition you have to make. Maven doesn't know about this. I would recommend using Major.Minor.Increment-Qualifier , etc. In my opinion, you should fix your versions, otherwise you will not be able to reproduce your builds.

+3
source

I would change the identifier of the artifact (perhaps by adding the major version number). This would make versions 1.x and 2.x different animals in Maven.

+1
source

Have you looked at the maven enforcer plugin? it may have something like this, or you can write your own rule.

0
source

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


All Articles