在没有pom.xml的情况下下载本地或全局存储库的maven依赖项

时间:2019-06-15 09:54:20

标签: maven pom.xml

我需要下载存储在各种Maven存储库中的文件(有时是全局的,有时在本地),但是我不在maven项目中,所以我没有pom.xml

也是解决方案 org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get

不起作用,因为我没有pom.xml。

edit:新版本和所有args仍然存在问题!

1 个答案:

答案 0 :(得分:1)

请完整阅读文档,并理解它,因为您不必拥有一个项目,这意味着要执行pom.xml

empty-project$ ls -al ~/.m2/repository/junit
ls: /Users/khmarbaise/.m2/repository/junit: No such file or directory

检查我使用的项目没有任何文件,也没有pom.xml

empty-project$ ls -la
total 0
drwxr-xr-x   2 khmarbaise  staff   64 Jun 15 14:28 .
drwxr-xr-x  12 khmarbaise  staff  384 Jun 15 14:28 ..
empty-project$ 

现在调用maven-dependency-plugin的dependency:get目标:

empty-project$ mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get -DartifactId=junit -DgroupId=junit -Dversion=3.8

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.1.1:get (default-cli) @ standalone-pom ---
Downloading from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8.1/junit-3.8.1.pom
Downloaded from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8.1/junit-3.8.1.pom (998 B at 13 kB/s)
Downloading from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8.1/junit-3.8.1.jar
Downloaded from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8.1/junit-3.8.1.jar (121 kB at 6.7 MB/s)
[INFO] Resolving junit:junit:jar:3.8 with transitive dependencies
Downloading from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8/junit-3.8.pom
Downloaded from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8/junit-3.8.pom (744 B at 106 kB/s)
Downloading from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8/junit-3.8.jar
Downloaded from nexus: http://localhost:8081/nexus/content/groups/public/junit/junit/3.8/junit-3.8.jar (122 kB at 8.1 MB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.118 s
[INFO] Finished at: 2019-06-15T14:33:23+02:00
[INFO] ------------------------------------------------------------------------

这将下载工件并放入您的本地缓存中。

您可以稍后查看:

empty-project$ ls -al ~/.m2/repository/junit
total 0
drwxr-xr-x    3 khmarbaise  staff    96 Jun 15 14:33 .
drwxr-xr-x  119 khmarbaise  staff  3808 Jun 15 14:33 ..
drwxr-xr-x    4 khmarbaise  staff   128 Jun 15 14:33 junit

所有maven插件文档都会告诉您是否需要一个项目,例如,https://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html是一个需要项目的目标(换言之,pom.xml文件)...

  

属性:

     

需要执行一个Maven项目。需要依赖   范围内工件的分辨率:测试。从版本开始:2.0-alpha-3。   在调用生命周期阶段测试编译之前执行   执行自己。

相关问题