Can maven handle custom qualifiers?
Asked Answered
S

2

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!

Stomato answered 15/8, 2011 at 23:54 Comment(1)
Possible duplicate of How does maven sort version numbers?Lions
C
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).

Cundiff answered 16/8, 2011 at 3:42 Comment(0)
L
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.

Lions answered 4/8, 2016 at 21:6 Comment(3)
Please don't add link only questions. At least, add a summary of the rules.Shroudlaid
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?Lions
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.Shroudlaid

© 2022 - 2024 — McMap. All rights reserved.