使用命令行从 Nexus 下载具有依赖项的 Maven 工件

may*_*ran 6 java nexus maven maven-jar-plugin maven-dependency-plugin

我正在使用下面的命令通过命令行从 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
Run Code Online (Sandbox Code Playgroud)

但我得到的是一个没有依赖关系的 jar。Maven 中已经有一个带有依赖项的 jar 名称update-service-1.0.4-jar-with-dependencies.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
Run Code Online (Sandbox Code Playgroud)

但它返回以下错误:

[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
Run Code Online (Sandbox Code Playgroud)

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

A_D*_*teo 4

jar-with-dependencies在本例中是 Maven classifier

分类器允许区分从相同 POM 构建但内容不同的工件。它是一些可选且任意的字符串,如果存在,则将其附加到版本号后面的工件名称中。

也就是说,1.0.4jar 及其依赖项变体通过分类器的 Maven 坐标有所不同。

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

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

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

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

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

您的artifact选择应如下所示:

-Dartifact=bits:update-service:1.0.4:jar:jar-with-dependencies
Run Code Online (Sandbox Code Playgroud)

注意:您在指定时实际上已经错误地使用了它:

-Dartifact=bits:update-service:1.0.3[:packaging[:jar]]
Run Code Online (Sandbox Code Playgroud)

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