Class VersionComparator

  • All Implemented Interfaces:
    Comparator<String>

    public class VersionComparator
    extends Object
    implements Comparator<String>
    Since as of version 3.6.6 Version.compareTo(Version) is incompatible with maven version ordering, this implements maven semantics. (it'll order e.g. 1.2.3-SNAPSHOT after 1.2.3, while 1.2.3 is the release that is created after all snapshots).

    The functionality is specifically:

    • mixing of '-' (hyphen) 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,
    • String qualifiers are ordered lexically (case insensitive), with the following exceptions:
      • 'snapshot' < '' < 'sp'
      and alias -> replacement (all case insensitive):
      • 'a' -> 'alpha'
      • 'b' -> 'beta'
      • 'm' -> 'milestone'
      • 'cr' -> 'rc'
      • 'final' -> ''
      • 'final' -> ''
      • 'final' -> ''
    • Following semver rules is encouraged, and some qualifiers are discouraged (no matter the case):
      • The usage of 'CR' qualifier is discouraged. Use 'RC' instead.
      • The usage of 'final', 'ga', and 'release' qualifiers is discouraged. Use no qualifier instead.
      • The usage of 'SP' qualifier is discouraged. Increment the patch version instead.
      For other qualifiers, natural ordering is used (case insensitive):
      • alpha = a < beta = b < milestone = m < rc = cr < snapshot < '' = final = ga = release < sp
    • a hyphen usually precedes a qualifier, and is always less important than digits/number, for example 1.0.RC2 < 1.0-RC3 < 1.0.1 ; but prefer '1.0.0-RC1' over '1.0.0.RC1'
    See Also:
    "https://github.com/apache/maven/blob/maven-3.8.6/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java"