How to specify version range for Maven dependency plugin on command line
I am trying to use the maven dependency plugin to get an artifact in a specific version range. I need to do this on the command line (or in a script)
Here's what I've tried:
mvn dependency:get -Dartifact="junit:junit:[4.0,4.11)"
However, the range does not appear to be recognized as such. Maven tries and fails to load artifact with literal version [4.0.0.4.11.0].
I am assuming that I am using the wrong syntax and / or not escaping correctly.
How can I get maven to get the highest version artifact that matches the specified version range?
Error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:get (default-cli) on project standalone-pom: Couldn't download artifact: Missing:
[ERROR] ----------
[ERROR] 1) junit:junit:jar:[4.0,4.11)
Version range is not supported for this purpose:
https://issues.apache.org/jira/browse/MDEP-88
I get:
Failed to retrieve POM for junit:junit:jar:[4.0,4.11): Could not transfer artifact junit:junit:pom:[4.0,4.11) from/to central (https://repo.maven.apache.org/maven2): Illegal character in path at index 49: https://repo.maven.apache.org/maven2/junit/junit/[4.0,4.11)/junit-[4.0,4.11).pom
Thus, the range is not analyzed.
Not sure if an alternative that does the same thing: /
version plugin allows to resolve ranges http://www.mojohaus.org/versions-maven-plugin/resolve-ranges-mojo.html but only inside pom.xml - need to create fake pom.xml - use this plugin to solve this version and then pull it out of the pump you created - there is hopefully a better way ...
To get around this situation, I did
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.group.name</groupId>
<artifactId>name-maven-plugin</artifactId>
<version>[x,]</version> <!-- use any range -->
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>com.group.name</groupId>
<artifactId>name-maven-plugin</artifactId>
<!-- specify no version -->
<configuration>
<!-- any config -->
</configuration>
</plugin>
....
The above, however, you get a missing version WARNING in the plugin, so this could potentially lead to a bug in a future version of Maven - as per the warning