簡體   English   中英

使用命令行從Nexus下載具有依賴性的Maven工件

[英]download of a Maven artifact with dependencies from Nexus using the command line

我正在使用以下命令通過命令行從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中已經有一個帶有依賴項的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

但它返回以下錯誤:

[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

分類器允許區分從相同POM構建但其內容不同的工件。 它是一些可選的任意字符串 - 如果存在 - 將附加到版本號之后的工件名稱。

也就是說, 1.0.4 jar及其with-dependencies變體通過分類器在Maven坐標上有所不同。

因此,使用maven-dependency-plugin及其get目標,您可以通過classifier選項指定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 )。

我已經創建了一個示例來向您展示方式。
我想在4.2.5.RELEASE版本中下載spring-webmvc的所有依賴項。
1)如果尚未在本地存儲庫中,則需要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

[INFO]掃描項目......
[警告]為org.springframework構建有效模型時遇到了一些問題:spring-webmvc:jar:4.2.5.RELEASE
...
[INFO] ----------------------------------------------- -------------------------
[INFO]構建Spring Web MVC 4.2.5.RELEASE
[INFO] ----------------------------------------------- -------------------------
[警告] com.lowagie的pOM:itext:jar:2.1.7.js4缺失,沒有可用的依賴項信息
[信息]
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies(default-cli)@ spring-webmvc ---
[警告] org.apache.maven.doxia的POM:doxia-sink-api:jar:1.0無效,傳遞依賴(如果有)將不可用,啟用調試日志記錄以獲取更多詳細信息
[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] ----------------------------------------------- -------------------------
[信息]建立成功
[INFO] ----------------------------------------------- -------------------------
[INFO]總時間:4.095秒
[INFO]完成於:2016-06-23T11:06:03 + 02:00
[INFO]最終記憶:14M / 241M
[INFO] ----------------------------------------------- -------------------------

結果:

C:\\ TEMP \\ spring_web_mvc> DIR
驅動器C中的卷沒有標簽。
卷序列號為F400-3CE5

C:\\ temp \\ spring_web_mvc目錄

2016/06/23 11:05
2016/06/23 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 ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM