How does the Central Repository sort version numbers?

蹲街弑〆低调 提交于 2019-12-02 07:40:55

This is a job for a classifier and not for that kind of weird version.

  • 2.6 with classifier: "jdk8" for JDK 8
  • 2.6 with classifier: "jdk7" etc.

Furthermore the referenced document of Oracle was valid for Maven 2 but not for Maven 3.

Apart from that I would suggest to increase the major version for such incombatible change based on semver.

Furthermore you are referencing the ComparableVersion with alpha etc. is how Maven internally handles the versions. This can looked at the Unit test for that class.

But you can check the behaviour of Maven via a little command line tool:

java -jar apache-maven-3.3.9\lib\maven-artifact-3.3.9.jar 1.0.0 2.0.0
Display parameters as parsed by Maven (in canonical form) and comparison result:
1. 1.0.0 == 1
   1.0.0 < 2.0.0
2. 2.0.0 == 2

By using this you can see that Maven 3+ handles 2.6-m-java7 as greater than 2.6.

java -jar apache-maven-3.3.9\lib\maven-artifact-3.3.9.jar 2.6-m-java7 2.6
Display parameters as parsed by Maven (in canonical form) and comparison result:
1. 2.6-m-java7 == 2.6-m-java-7
   2.6-m-java7 > 2.6
2. 2.6 == 2.6

So this is the reason why central also handles it as greater.

So if you use things like rc or alpha you will see the result:

java -jar apache-maven-3.3.9\lib\maven-artifact-3.3.9.jar 2.6-alpha 2.6
Display parameters as parsed by Maven (in canonical form) and comparison result:
1. 2.6-alpha == 2.6-alpha
   2.6-alpha < 2.6
2. 2.6 == 2.6

java -jar apache-maven-3.3.9\lib\maven-artifact-3.3.9.jar 2.6-rc1 2.6
Display parameters as parsed by Maven (in canonical form) and comparison result:
1. 2.6-rc1 == 2.6-rc-1
   2.6-rc1 < 2.6
2. 2.6 == 2.6

(The above CLI tool is available since Maven 3.2.5).

The best solution is to have a module which produces your usual artifact. Making a supplemental module which contains the configuration for JDK 7 and there you can use "threeten backport" and create an other artifact. Those artifacts should have classifiers for such purposes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!