【问题标题】:How do i specify a version range for Maven dependency plugin get on command line如何在命令行上指定 Maven 依赖插件的版本范围
【发布时间】:2015-09-09 11:50:45
【问题描述】:

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

这是我尝试过的:

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

但是,范围显然不被识别。 Maven 尝试下载具有 [4.0.0,4.11.0) 的文字版本的工件。

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

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

错误信息:

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

【问题讨论】:

    标签: maven dependencies maven-3


    【解决方案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
    

    所以范围没有被解析。

    不确定有什么替代方案可以做同样的事情:/

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

    【讨论】:

      【解决方案2】:

      为了解决我遇到的类似情况

         <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 版本中出错 - 根据警告

      【讨论】:

      • 问题提到依赖版本而不是插件版本
      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      • 2016-03-25
      • 2014-10-26
      • 2016-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多