简体   繁体   English

如何在不使用依赖项的情况下在命令行下载 Maven 工件:get 或 maven-download-plugin?

[英]How do I download a Maven artifact at the command line without using dependency:get or maven-download-plugin?

I'd like to download an artifact and its dependencies at the command line.我想在命令行下载工件及其依赖项。 Ie IE

mvn [some plugin]:[goal] -DartifactId=[artifactId] -DgroupId=[groupId] -Dversion=[version]

I've tried mvn dependency:get but this seems to require a list of remote repositories.我试过 mvn dependency:get 但这似乎需要一个远程存储库列表。 I want mvn to use what's already specified in settings.xml我希望 mvn 使用 settings.xml 中已经指定的内容

I've also tried the maven-download-plugin but this doesn't seem to work properly (it tried downloading xerces-impl as a transitive dependency of ant and failed to resolve it. Neither xerces-impl nor ant are dependencies of my artifact).我也试过maven-download-plugin但这似乎不能正常工作(它尝试下载 xerces-impl 作为 ant 的传递依赖项,但未能解决它。xerces-impl 和 ant 都不是我的工件的依赖项)。

Your help would be appreciated.您的帮助将不胜感激。

The copy goal is more appropriate here and it lets you specify an output directory as well (which is deprecated in the get goal): copy目标在这里更合适,它也允许您指定输出目录(在get目标中已弃用):

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=groupId:artifactId:version[:packaging][:classifier] -DoutputDirectory=[target] -Dmdep.useBaseVersion=true

mdep.useBaseVersion=true will remove timestamps from snapshot builds. mdep.useBaseVersion=true将从快照构建中删除时间戳。

Try using the latest version of dependency:get, it works for me尝试使用最新版本的依赖:get,它对我有用

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DartifactId=[artifactId] -DgroupId=[groupId] -Dversion=[version]

works for me为我工作

Example to download version 6.9.4 of TestNG to your local ~/.m2/repository (uses maven-dependency-plugin:get):将 TestNG 6.9.4 版本下载到本地 ~/.m2/repository 的示例(使用 maven-dependency-plugin:get):

mvn org.apache.maven.plugins:maven-dependency-plugin:RELEASE:get \
-Dartifact=org.testng:testng:6.9.4:jar

Example to download version 4.11 of JUnit to your current working directory (uses maven-dependency-plugin:copy):将 JUnit 4.11 版下载到当前工作目录的示例(使用 maven-dependency-plugin:copy):

mvn org.apache.maven.plugins:maven-dependency-plugin:RELEASE:copy \
-Dartifact=junit:junit:4.11:jar

最简单的解决方案是创建一个具有适当依赖项的简单 pom 并在该迷你项目上执行 mvn clean package ...

this is the method that I use, matches your need but less typing and brain cell consumption:这是我使用的方法,符合您的需要,但打字和脑细胞消耗较少:

curl https://start.spring.io/starter.tgz | tar -xzvf -

(btw, you can add -d dependencies=lombok when the dependency you want is listed on starter like lombok.) (顺便说一句,当您想要的依赖项在像 lombok 这样的启动器上列出时,您可以添加-d dependencies=lombok lombok。)

And then, in vim pom.xml , delete whatever parent and modify everything between dependencies.然后,在vim pom.xml ,删除任何父项并修改依赖项之间的所有内容。 you just need to fill in group, artifact and version.你只需要填写组,工件和版本。

Finally, mvn package .最后, mvn package It starts to download...它开始下载...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM