gpt4 book ai didi

java - 使用命令行从 Nexus 下载具有依赖项的 Maven Artifact

转载 作者:搜寻专家 更新时间:2023-11-01 03:00:00 27 4
gpt4 key购买 nike

我正在使用下面的命令通过命令行从 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 的正确方法是什么?

最佳答案

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

The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.

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

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

The classifier of the artifact to download. Ignored if artifact is used.

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

A string of the form 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)。

关于java - 使用命令行从 Nexus 下载具有依赖项的 Maven Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985286/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com