How do I download a Maven artifact at the command

2019-01-21 22:40发布

I'd like to download an artifact and its dependencies at the command line. I.e.

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. I want mvn to use what's already specified in 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).

Your help would be appreciated.

4条回答
我想做一个坏孩纸
2楼-- · 2019-01-21 23:09

Example to download version 6.9.4 of TestNG to your local ~/.m2/repository (uses 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):

mvn org.apache.maven.plugins:maven-dependency-plugin:RELEASE:copy \
-Dartifact=junit:junit:4.11:jar
查看更多
叛逆
3楼-- · 2019-01-21 23:12

The copy goal is more appropriate here and it lets you specify an output directory as well (which is deprecated in the get goal):

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.

查看更多
叛逆
4楼-- · 2019-01-21 23:25

The simplest solution would be to create a simple pom with the appropriate dependencies and do mvn clean package on that mini project...

查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-21 23:33

Try using the latest version of dependency:get, it works for me

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

works for me

查看更多
登录 后发表回答