Maven如何排序版本号? [英] How does maven sort version numbers?

查看:247
本文介绍了Maven如何排序版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven似乎能够指出诸如<version>[1.2.3,)</version>之类的一系列版本,当没有所有开源软件包都遵循的一致版本控制方案时,maven如何确定是较新的版本还是较旧的版本.例如

Maven seems to have the ability to indicate a range of versions such as <version>[1.2.3,)</version> how does maven figure out what is a newer or older version when there is no consistent versioning scheme that all open source packages follow. For example

  • junit 4.10
  • slf4j 1.7.2
  • 休眠4.1.7.Final
  • 春天3.1.2.RELEASE
  • junit 4.10
  • slf4j 1.7.2
  • Hibernate 4.1.7.Final
  • Spring 3.1.2.RELEASE

maven如何确定maven中软件包的旧版本和新版本?如果程序包使用字母作为版本号,则沿A,B,C或A2,A2,A4 ...的行编号怎么办?

How does maven figure what is an older vs. newer version of a package in maven? What if package uses letters as versions numbers something along the lines of A,B,C or A2,A2,A4 ... etc.

在Maven中应该有一种标准的正式版本软件包吗?像spring和hibernate这样的通用开源软件包会忽略此版本控制约定吗?

Is there supposed to be a standard official way to version packages in maven? Are common open source packages like spring and hibernate ignoring this versioning convention?

推荐答案

从版本3.0开始,Maven使用一致的系统来比较各个版本和版本范围的版本号.一旦您了解了一些陷阱,现在该系统就变得很有道理了.

Since version 3.0, Maven uses a consistent system to compare version numbers for both individual versions and version ranges. The system now makes a lot of sense, once you've understood a few gotchas.

所有比较现在都由可比较版本,其中说:

All comparisons are now done by ComparableVersion, which says:

  • '-'(破折号)和'.'(点破号)分隔符的混合,
  • 字符和数字之间的转换也构成分隔符:1.0alpha1 => [1, 0, alpha, 1]
  • 无限数量的版本组件,
  • 文本中的
  • 版本组件可以是数字或字符串,
  • 将检查
  • 字符串是否包含众所周知的限定符,并将限定符排序用于版本排序.众所周知的限定词(不区分大小写)是:
    • alphaa
    • betab
    • milestonem
    • rccr
    • snapshot
    • (空字符串)或gafinal
    • sp
  • mixing of '-' (dash) and '.' (dot) separators,
  • transition between characters and digits also constitutes a separator: 1.0alpha1 => [1, 0, alpha, 1]
  • unlimited number of version components,
  • version components in the text can be digits or strings,
  • strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering. Well-known qualifiers (case insensitive) are:
    • alpha or a
    • beta or b
    • milestone or m
    • rc or cr
    • snapshot
    • (the empty string) or ga or final
    • sp

这意味着版本按照以下顺序列出,除了中间的1.0-SNAPSHOT,我认为这很合理:

This means that versions come out in the following order, which I think makes perfect sense, apart from 1.0-SNAPSHOT right in the middle:

  • 1.0-beta1-SNAPSHOT
  • 1.0-beta1
  • 1.0-beta2-SNAPSHOT
  • 1.0-rc1-SNAPSHOT
  • 1.0-rc1
  • 1.0-SNAPSHOT
  • 1.0
  • 1.0-sp
  • 1.0-whatever
  • 1.0.1
  • 1.0-beta1-SNAPSHOT
  • 1.0-beta1
  • 1.0-beta2-SNAPSHOT
  • 1.0-rc1-SNAPSHOT
  • 1.0-rc1
  • 1.0-SNAPSHOT
  • 1.0
  • 1.0-sp
  • 1.0-whatever
  • 1.0.1

我在所有这方面发现的主要问题是snapshot出现在之后 betarc,所以您不能使用1.0-SNAPSHOT的开发版本,然后发布1.0-beta11.0-rc1并让Maven知道以后会出现.

The main gotcha I found in all this is that snapshot comes after beta or rc, so you can't have a development version of 1.0-SNAPSHOT, then release 1.0-beta1 or 1.0-rc1 and have Maven understand that those are later.

还要注意,1.0-beta-11.0beta1完全相同,而1.011.0.0完全相同.

Also note that 1.0-beta-1 is exactly the same as 1.0beta1, and 1.0 is exactly the same as 1 or 1.0.0.

现在,版本范围也(几乎)以您期望的方式工作.例如,[1.0-alpha-SNAPSHOT,1.0]将找到1.0-beta1-SNAPSHOT1.0-beta11.0-rc1-SNAPSHOT1.0-rc11.0-SNAPSHOT1.0,比起较早的项目更喜欢较晚的项目. mvn versions:resolve,M2Eclipse等完全支持.

Version ranges now work (nearly) the way you'd expect, too. For example, [1.0-alpha-SNAPSHOT,1.0] will find 1.0-beta1-SNAPSHOT, 1.0-beta1, 1.0-rc1-SNAPSHOT, 1.0-rc1, 1.0-SNAPSHOT or 1.0, preferring later items over earlier ones. This is fully supported by mvn versions:resolve, M2Eclipse and so on.

这篇关于Maven如何排序版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆