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

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

问题描述

Maven 似乎有能力指示一系列版本,例如 [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
  • 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.

所有比较现在都由 ComparableVersion,其中说:

All comparisons are now done by ComparableVersion, which says:

  • 混合使用 '-'(破折号)和 '.'(点)分隔符,
  • 字符和数字之间的转换也构成了分隔符:1.0alpha1 => [1, 0, alpha, 1]
  • 无限数量的版本组件,
  • 文本中的版本组件可以是数字或字符串,
  • 检查字符串是否有众所周知的限定符,并且限定符排序用于版本排序.众所周知的限定符(不区分大小写)是:
    • alphaa
    • betab
    • 里程碑m
    • rccr
    • 快照
    • (空字符串)或 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-随便
    • 1.0.1

    我在这一切中发现的主要问题是 snapshot after 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.0完全一样11.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-SNAPSHOT, 1.0-beta1, 1.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天全站免登陆