Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

like image 556
Chris Beach Avatar asked Jun 29 '12 13:06

Chris Beach


People also ask

How do I download specific dependencies in Maven?

You can use the Maven Dependency Plugin to download dependencies. Run mvn dependency:copy-dependencies , to download all your dependencies and save them in the target/dependency folder. You can change the target location by setting the property outputDirectory .

Why does Maven always download dependency?

When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository. It helps to avoid references to dependencies stored on remote machine every time a project is build. Maven local repository by default get created by Maven in %USER_HOME% directory.


1 Answers

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.

like image 158
Gili Avatar answered Sep 28 '22 16:09

Gili