中央存储库如何对版本号进行排序? [英] How does the Central Repository sort version numbers?
问题描述
我维护一个开源项目,并将其发行版发布到中央存储库.我刚刚发布了oshi-core-2.6
.我的pom.xml
中该版本的版本为:
I maintain an open source project and publish its releases to The Central Repository. I just published oshi-core-2.6
. The versioning in my pom.xml
for that release reads:
<groupId>com.github.dblock</groupId>
<artifactId>oshi-core</artifactId>
<version>2.6</version>
由于日期/时间功能,我的代码需要Java 8.为了支持用户的请求,就在此发行版之前,我使用Threeten反向端口发布了Java 7兼容版本,其pom.xml
中带有以下内容:
My code requires Java 8 due to the Date/Time functions. To support a user's request, just prior to this release, I released a Java 7 compatible version using the threeten backport, with the following in its pom.xml
:
<groupId>com.github.dblock</groupId>
<artifactId>oshi-core</artifactId>
<version>2.6-m-java7</version>
版本号如何在Maven中工作状态所有带有限定符的版本都比没有限定符的相同版本(发行版)更早."另一个StackOverflow问题 maven如何对版本号进行排序?,给出了一个答案. ComparableVersion 类,其中列出了几个众所周知的限定符(alpha,beta,里程碑,rc和快照),它们应该比ga/final(空字符串)版本早"排序.
How Version Numbers Work in Maven states that "All versions with a qualifier are older than the same version without a qualifier (release version)." Another StackOverflow question, How does maven sort version numbers?, has an answer citing the ComparableVersion class which lists several well-known qualifiers (alpha, beta, milestone, rc, and snapshot) which are supposed to sort "earlier" than the ga/final (empty string) release.
由于在早期版本中具有自定义限定符,我尝试使用java7版本中的里程碑限定符(-m-
)向Maven指示它应为2.6之前的较早"发行版.但是,搜索中央存储库显示了-m-
版本是最新版本".
Having been bit by having a custom qualifier in an earlier version, I tried to use the milestone qualifier (-m-
) in my java7 version to indicate to Maven that it should be an "earlier" release than 2.6. However, searching the Central Repository shows that the -m-
version is the "Latest Version".
我有问题:
- 为什么中央存储库排序与我上面链接的记录排序不匹配?
- 是否使用Maven排序的早期版本(3.2之前的版本)?如果是这样,我可以期待什么一致的最新版本"排序?
- 我的工件名称中的连字符是否有影响?
- Why does the Central Repository sorting not match the documented sorting I've linked above?
- Is it using an earlier version (pre-3.2) of Maven's sorting? If so, what consistent "Latest Version" sorting can I expect?
- Does the hyphen in my artifact name have any impact?
推荐答案
这是分类器的工作,而不是那种奇怪的版本.
This is a job for a classifier and not for that kind of weird version.
- 带有分类器的2.6:用于JDK 8的"jdk8"
- 2.6,带有分类器:"jdk7"等.
此外,Oracle的参考文档对Maven 2有效,但对Maven 3无效.
Furthermore the referenced document of Oracle was valid for Maven 2 but not for Maven 3.
除此之外,我建议根据 semver 来增加这种不可更改的更改的主要版本.
Apart from that I would suggest to increase the major version for such incombatible change based on semver.
此外,您还使用Alpha等引用ComparableVersion,这是Maven在内部处理版本的方式.这可以查看
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.
但是您可以通过一个小的命令行工具来检查Maven的行为:
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
使用此功能,您可以看到Maven 3+处理的
2.6-m-java7
大于2.6
.By using this you can see that Maven 3+ handles
2.6-m-java7
as greater than2.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
所以这就是为什么Central也将其处理得更大的原因.
So this is the reason why central also handles it as greater.
因此,如果您使用
rc
或alpha
之类的东西,您将看到结果:So if you use things like
rc
oralpha
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
(上面的CLI工具从Maven 3.2.5开始可用).
(The above CLI tool is available since Maven 3.2.5).
最好的解决方案是拥有一个可以产生您通常的工件的模块.制作一个包含JDK 7的配置的补充模块,您可以在其中使用第三反向移植"并创建另一个工件.这些工件应具有用于此类目的的分类器.
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.
这篇关于中央存储库如何对版本号进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!