使用命令行从Nexus下载带依赖的Maven构件

7
我正在使用以下命令通过命令行从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包?

2个回答

4
在这种情况下,jar-with-dependencies是Maven中的分类器
分类器允许区分从相同POM构建但内容不同的工件。它是一些可选的任意字符串,如果存在,则会附加到版本号后面的工件名称。
也就是说,1.0.4 jar及其with-dependencies变体通过分类器在其Maven坐标中有所不同。
因此,使用maven-dependency-plugin及其get目标,您可以通过分类器选项指定分类器:
要下载的工件的分类器。如果使用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)。

1
我已经创建了一个示例,以展示给您这种方法。
我想下载spring-webmvc版本4.2.5.RELEASE的所有依赖项。
1)如果本地仓库中不存在spring-webmvc,则需要webmvc的pom。如果spring-webmvc已经在本地存储库中,则跳过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" 这是一个命令行代码,用于将依赖项复制到指定目录。下方的文本是执行结果,其中包含一些警告和信息。

结果:

C:\temp\spring_web_mvc>dir
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 ...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接