【问题标题】:download of a Maven artifact with dependencies from Nexus using the command line使用命令行从 Nexus 下载具有依赖项的 Maven 工件
【发布时间】:2016-06-23 07:47:55
【问题描述】:

我正在使用以下命令通过命令行从 Nexus 下载 maven jar。

call mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DrepoUrl=http://10.101.15.190:8081/nexus/content/repositories/releases/ -Dartifact=bits:update-service:1.0.3 -Ddest=Setups/Services/update-service.jar

但我得到的是一个没有依赖关系的 jar。 Maven 中已经有一个名为 update-service-1.0.4-jar-with-dependencies.jar 的 jar 依赖项

我尝试了以下方法:

call mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DrepoUrl=http://10.101.15.190:8081/nexus/content/repositories/releases/ -Dartifact=bits:update-service:1.0.3[:packaging[:jar]] -Ddest=Setups/Services/update-service.jar

但它返回以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.4:get (default-cli) on project standalone-pom: Couldn't download artifact: Missing:
[ERROR] ----------
[ERROR] 1) bits:update-service:packaging[:jar]]:1.0.3[
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=bits -DartifactId=update-service -Dversion=1.0.3[ -Dclassifier=jar]] -Dpackaging=packaging[ -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=bits -DartifactId=update-service -Dversion=1.0.3[ -Dclassifier=jar]] -Dpackaging=packaging[ -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR] Path to dependency:
[ERROR] 1) org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
[ERROR] 2) bits:update-service:packaging[:jar]]:1.0.3[
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR]
[ERROR] for artifact:
[ERROR] org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false),
[ERROR] temp (http://10.101.15.190:8081/nexus/content/repositories/releases/, releases=true, snapshots=true)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

问题:下载带有依赖项的jar的正确方法是什么?

【问题讨论】:

    标签: java maven nexus maven-dependency-plugin maven-jar-plugin


    【解决方案1】:

    jar-with-dependencies 在这种情况下是一个 Maven classifier

    分类器允许区分从同一个 POM 构建但内容不同的工件。它是一些可选且任意的字符串,如果存在的话,它会被附加到工件名称之后,紧跟在版本号之后。

    也就是说,1.0.4 jar 及其 with-dependencies 变体通过分类器在它们的 Maven 坐标上有所不同。

    因此,使用maven-dependency-plugin 及其get 目标,您可以通过classifier 选项指定classifier

    要下载的工件的分类器。如果使用artifact,则忽略。

    但是,您确实已经在使用 artifact 选项,因此根据文档,上述选项将被忽略。
    如果您查看 artifact 选项的文档:

    groupId:artifactId:version[:packaging][:classifier] 形式的字符串。

    查看它的最后一个(可选)令牌[:classifier]。这正是您所缺少的。

    您的artifact 选项应如下所示:

    -Dartifact=bits:update-service:1.0.4:jar:jar-with-dependencies
    

    注意:你在指定的时候其实已经用错了:

    -Dartifact=bits:update-service:1.0.3[:packaging[:jar]]
    

    方括号[..] 表示可选参数,您不应在命令行调用中指定它们。此外,那里的packaging 字符串指定了要放置的值:同样,您不应该指定它,而只需将其替换为相应的值(在本例中为jar)。

    【讨论】:

      【解决方案2】:

      我创建了一个示例来向您展示方法。
      我想下载4.2.5.RELEASE版本的spring-webmvc的所有依赖。
      1) 如果本地存储库中还没有 webmvc 的 pom,则需要它。如果 spring-webmvc 已经在本地 repo 中,则跳过 1)。
      2) 您可以下载与您刚刚下载的 pom 相关的所有依赖项。

      1. 下载 pom

      C:\temp\spring_web_mvc>mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get -DgroupId=org.springframework -DartifactId=spring-webmvc -Dversion=4.2.5.RELEASE -Dtype=pom

      1. 下载所有依赖项

      C:\temp\spring_web_mvc>mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies -f C:\repository2\org\springframework\spring-webmvc\4.2.5.RELEASE \spring-webmvc-4.2.5.RELEASE.pom -DoutputDirectory=C:\TEMP

      [INFO] 正在扫描项目...
      [警告] 为org.springframework:spring-webmvc:jar:4.2.5.RELEASE构建有效模型时遇到一些问题
      ...
      [信息] --------------------------------------------- ----------------------------
      [INFO] 构建 Spring Web MVC 4.2.5.RELEASE
      [信息] --------------------------------------------- ----------------------------
      [警告] com.lowagie:itext:jar:2.1.7.js4 的 POM 丢失,没有可用的依赖信息
      [信息]
      [INFO] --- maven-dependency-plugin:2.10:copy-dependencies (default-cli) @ spring-webmvc ---
      [警告] org.apache.maven.doxia:doxia-sink-api:jar:1.0 的 POM 无效,传递依赖(如果有)将不可用,请启用调试日志以获取更多详细信息
      [INFO] org.apache.tiles:tiles-request-mustache:jar:1.0.6 已存在于目标中。
      [INFO] com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.6.5 已存在于目的地。
      [INFO] org.apache.tiles:tiles-mvel:jar:3.0.5 已存在于目标中。
      [INFO] org.apache.tiles:tiles-jsp:jar:2.2.2 已存在于目标中。
      [INFO] org.jfree:jcommon:jar:1.0.23 已存在于目标中。
      ...
      [INFO] org.apache.tiles:tiles-extras:jar:3.0.5 已存在于目标中。
      [信息] --------------------------------------------- ----------------------------
      [信息] 构建成功
      [信息] --------------------------------------------- ----------------------------
      [INFO] 总时间:4.095 秒
      [INFO] 完成于:2016-06-23T11:06:03+02:00
      [INFO] 最终内存:14M/241M
      [信息] --------------------------------------------- ----------------------------

      结果:

      C:\temp\spring_web_mvc>目录
      驱动器 C 中的卷没有标签。
      卷序列号为 F400-3CE5

      C:\temp\spring_web_mvc 目录

      23/06/2016 11:05 。
      23/06/2016 11:05 ..
      23/06/2016 10:24 4,467 aopalliance-1.0.jar
      23/06/2016 10:24 192,035 bcmail-jdk14-1.38.jar
      23/06/2016 10:24 192,035 bcmail-jdk14-138.jar ...

      【讨论】:

        猜你喜欢
        • 2014-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-24
        • 2013-03-05
        • 2012-07-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多