如何为命令行指定Maven依赖插件的版本范围

时间:2015-06-23 15:20:15

标签: maven dependencies maven-3

我正在尝试使用maven依赖插件来获取特定版本范围内的工件。我需要在命令行(或脚本)中执行此操作

这是我试过的:

mvn dependency:get -Dartifact="junit:junit:[4.0,4.11)"

然而,该范围显然未被认可。 Maven尝试并无法下载文字版 [4.0.0,4.11.0)的工件。

我想我使用了错误的语法和/或没有正确转义。

如何让获取具有符合指定版本范围的最高版本的工件?

错误讯息:

[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)

2 个答案:

答案 0 :(得分:1)

此目标不支持版本范围:

https://issues.apache.org/jira/browse/MDEP-88

我明白了:

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

因此不会解析范围。

不确定做同样事情的替代方案:/

版本插件允许解析范围http://www.mojohaus.org/versions-maven-plugin/resolve-ranges-mojo.html但只在pom.xml中 - 需要创建一个假的pom.xml - 使用此插件解析版本,然后从创建的pom中获取 - 希望有更好的方式......

答案 1 :(得分:1)

要解决类似的情况我做了

   <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>
....

以上工作但是你得到一个关于插件中缺失版本的警告,因此可能会在未来的Maven版本中出错 - 根据警告