Benny Bottema
Benny Bottema

Reputation: 11493

Maven version range picking up unexpected dependency

I'm having a dependency defined with a version range:

<properties>
    <tomcat.version>[8.0.33,9.0.0)</tomcat.version>
</properties>

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    <version>${tomcat.version}</version>
    <scope>provided</scope>
</dependency>

Reading up on maven versions, I expected it to be of the "[1.0,2.0) -> 1.0 <= x < 2.0" variety. But a dependency:tree results in the following resolved version:

+- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.0.M9:provided

How can I tell Maven to use any Major 8 version starting at incremental version 33? I'm currently working around it by using [8.0.33,8.5.4] instead.

Upvotes: 4

Views: 1087

Answers (2)

Jesse
Jesse

Reputation: 3829

Maven absolute comparisons between version numbers when resolving a version range. ie. It compares the version exactly as they are, not what you meant.

That means that version 9.0.0.M9 is considered less than 9.0.0 and so is part of the range [8.0.33,9.0.0).

I have created issue MNG-5353 to exclude pre-release version numbers when comparing exclusive upper bounds, but this has not been implemented yet.

Excluding pre-release versions when comparing an exclusive upper bound would allow you to specify semantic version ranges in the form you used: [8.0.33,9.0.0).

In the mean time, you can use something like: [8.0.33,8.999.999] to define a semantic version range.

Upvotes: 1

khmarbaise
khmarbaise

Reputation: 97359

You can check the how version comparsion results in Maven via the folloing command line:

java -jar apache-maven-3.3.9/lib/maven-artifact-3.3.9.jar 9.0.0 9.0.0.M9

which results in the following:

Display parameters as parsed by Maven (in canonical form) and comparison result:
1. 9.0.0 == 9
   9.0.0 > 9.0.0.M9
2. 9.0.0.M9 == 9.0.0.milestone-9

which shows that 9.0.0 is greater than 9.0.0.M9 ...which means the result you got was correct.

Upvotes: 2

Related Questions