9

I'm trying to figure out if what Maven's policy is on custom qualifiers. I know that there exists specific qualifiers in Version strings that maven checks for, such as:

1.0.0-SNAPSHOT

5.3.0-beta-5

etc, but I was wondering if I could write specific rules or something that could handle custom qualifiers, such as:

1.0.0-mybranch

5.3.0-myotherbranch

or how maven would deal with such version strings. I've tried them out and things seem to be ok, I'm just wondering if Maven has some custom logic that could be used.

Thanks!

DrakeAnderson
  • 492
  • 4
  • 12
  • Possible duplicate of [How does maven sort version numbers?](https://stackoverflow.com/questions/13004443/how-does-maven-sort-version-numbers) – user7610 Feb 06 '19 at 14:35

2 Answers2

8

These examples will work fine.

Qualifiers have no special meaning other than:

  • SNAPSHOT, which gets transformed into the correct timestamp / build number
  • solely numerical values, which are actually a build number instead of a qualifier (and considered newer than the corresponding base version)

All qualifiers are considered to be older than the associated release, i.e. 1.2-beta-1 < 1.2

Comparison of qualifiers is done as a string comparison. This behaviour can differ in Maven 2.x and Maven 3.x (in the former, 1.0-beta-10 < 1.0-beta-5, in the latter it behaves in the reverse as you'd expect).

Brett Porter
  • 5,827
  • 27
  • 25
7

The 2011 answer is now obsolete in many important details. See the Javadoc on https://maven.apache.org/ref/3.3.9/maven-artifact/apidocs/org/apache/maven/artifact/versioning/ComparableVersion.html and the Wiki link there for the current version processing logic.

c.f. How does maven sort version numbers? for commentary on the Javadoc for ComparableVersion.

user7610
  • 25,267
  • 15
  • 124
  • 150
  • Please don't add link only questions. At least, add a summary of the rules. – PhoneixS Feb 06 '19 at 11:38
  • This is essentially a "go read the source code" answer. I think that the structure of the link is sufficient indicator for class to look for in sources if the link ever goes down. The linked question has the current details in full. Maybe lets close this one as duplicate? – user7610 Feb 06 '19 at 14:32
  • You can vote it for sure. Although, in my personal opinion, it's a bit different question. If I were you I would simply add the information related to the use of custom qualifiers for Maven 3. But it's discouraged to make link-only answers despite being a link to a good text. Instead of writing a complete answer, you could add the links as a comment to the original answer too. – PhoneixS Feb 06 '19 at 15:53