Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Info
titleNote

page copied from MAVENOLD to MAVEN here

issue tracked as MNG-3010

Improve default support for version schemes

...

The unit tests that are there to test comparison only check for a few cases with snapshots. When all tests
(version A < version B) are expanded to also test for SNAPSHOTs (version A-SNAPSHOT < version B-SNAPSHOT) a
lot of the tests fail.

Left

Op

Right

 


Left

Op

Right

 

 



1

=

1

(tick)

1-SNAPSHOT

=

1-SNAPSHOT

(tick)

 


1

<

2

(tick)

1-SNAPSHOT

<

2-SNAPSHOT

(tick)

 


1.5

<

2

(tick)

1.5-SNAPSHOT

<

2-SNAPSHOT

(tick)

 


1

<

2.5

(tick)

1-SNAPSHOT

<

2.5-SNAPSHOT

(tick)

 


1

=

1.0

(tick)

1-SNAPSHOT

=

1.0-SNAPSHOT

(tick)

 


1

=

1.0.0

(tick)

1-SNAPSHOT

=

1.0.0-SNAPSHOT

(tick)

 


1.0

<

1.1

(tick)

1.0-SNAPSHOT

<

1.1-SNAPSHOT

(tick)

 


1.1

<

1.2

(tick)

1.1-SNAPSHOT

<

1.2-SNAPSHOT

(tick)

 


1.0.0

<

1.1

(tick)

1.0.0-SNAPSHOT

<

1.1-SNAPSHOT

(tick)

 


1.1

<

1.2.0

(tick)

1.1-SNAPSHOT

<

1.2.0-SNAPSHOT

(tick)

 


1.0-alpha-1

<

1.0

(tick)

1.0-alpha-1-SNAPSHOT

<

1.0-SNAPSHOT

(error)

 


1.0-alpha-1

<

1.0-alpha-2

(tick)

1.0-alpha-1-SNAPSHOT

<

1.0-alpha-2-SNAPSHOT

(tick)

 


1.0-alpha-1

<

1.0-beta-1

(tick)

1.0-alpha-1-SNAPSHOT

<

1.0-beta-1-SNAPSHOT

(tick)

 


1.0

<

1.0-1

(tick)

1.0-SNAPSHOT

<

1.0-1-SNAPSHOT

(error)

 


1.0-1

<

1.0-2

(tick)

1.0-1-SNAPSHOT

<

1.0-2-SNAPSHOT

(error)

 


2.0-0

=

2.0

(tick)

2.0-0-SNAPSHOT

=

2.0-SNAPSHOT

(error)

 


2.0

<

2.0-1

(tick)

2.0-SNAPSHOT

<

2.0-1-SNAPSHOT

(error)

 


2.0.0

<

2.0-1

(tick)

2.0.0-SNAPSHOT

<

2.0-1-SNAPSHOT

(error)

 


2.0-1

<

2.0.1

(tick)

2.0-1-SNAPSHOT

<

2.0.1-SNAPSHOT

(tick)

 


2.0.1-klm

<

2.0.1-lmn

(tick)

2.0.1-klm-SNAPSHOT

<

2.0.1-lmn-SNAPSHOT

(tick)

 


2.0.1-xyz

<

2.0.1

(tick)

2.0.1-xyz-SNAPSHOT

<

2.0.1-SNAPSHOT

(error)

notice that the proposal reverted the order: in Maven 2, 2.0.1-xyz < 2.0.1 but in Maven 3, 2.0.1 < 2.0.1-xyz

2.0.1

<

2.0.1-123

(tick)

2.0.1-SNAPSHOT

<

2.0.1-123-SNAPSHOT

(error)

 


2.0.1-xyz

<

2.0.1-123

(tick)

2.0.1-xyz-SNAPSHOT

<

2.0.1-123-SNAPSHOT

(error)

 


Proposal

I'm proposing the following implementation: GenericArtifactVersion.java (unit test: GenericArtifactVersionTest.java). It has been integrated in artifact 3.0-SNAPSHOT r656775(15/5/2008) as ComparableVersion.java.

...

ordering rules when comparing version components:

...


Integer

String

List

null

Integer

Highest is newer

Integer is newer

Integer is newer

If integer==0 then equal,
otherwise integer is newer

String

Integer is newer

order by well-known
qualifiers and lexically
(see below)

List is newer

 Compare with ""

List

Integer is newer

List is newer 

Version itself is a list; compare item by item

Compare with empty list item (recursion)
this will finally result in String==?null or
Integer==?null

null

If integer==0 then equal,
otherwise integer is newer

Compare with "" 

Compare with empty list item (recursion)
this will finally result in String==?null or
Integer==?null

doesn't happen

Special note on string comparing:
A predefined list of well-known qualifiers is present. For comparison, the string is converted to another string, as follows:

...