Using Maven to download dependencies to a directory on the command line

Solution 1:

Apache ivy can be run as a standalone jar to download Maven dependencies. No POM required.

curl -L -O http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar
java -jar ivy-2.3.0.jar -dependency org.jclouds.provider rackspace-cloudservers-us 1.5.8 -retrieve "lib/[artifact]-[revision](-[classifier]).[ext]"

Produces the following files:

├── ivy-2.3.0.jar
└── lib
    ├── aopalliance-1.0.jar
    ├── asm-3.1.jar
    ├── bcprov-jdk16-1.46.jar
    ├── cglib-2.2.1-v20090111.jar
    ├── clojure-1.3.0.jar
    ├── core.incubator-0.1.0.jar
    ├── gson-2.2.jar
    ├── guava-13.0.jar
    ├── guice-3.0.jar
    ├── guice-assistedinject-3.0.jar
    ├── javax.inject-1.jar
    ├── jclouds-compute-1.5.8.jar
    ├── jclouds-core-1.5.8.jar
    ├── jclouds-scriptbuilder-1.5.8.jar
    ├── jsr250-api-1.0.jar
    ├── jsr311-api-1.1.1.jar
    ├── openstack-keystone-1.5.8.jar
    ├── openstack-nova-1.5.8.jar
    ├── rackspace-cloudidentity-1.5.8.jar
    ├── rackspace-cloudservers-us-1.5.8.jar
    ├── rackspace-cloudservers-us-1.5.8-javadoc.jar
    ├── rackspace-cloudservers-us-1.5.8-sources.jar
    ├── rocoto-6.1.jar
    └── tools.logging-0.2.3.jar

Solution 2:

The first command almost gets you what you need - the POM of the dependency in question. Once you have that, you should not need a further project POM to run copy:dependencies:

Here's an example:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.7:get -DgroupId=org.jclouds.provider -DartifactId=rackspace-cloudservers-us -Dversion=1.5.8 -Dtype=pom

mvn org.apache.maven.plugins:maven-dependency-plugin:2.7:copy-dependencies -f /path/to/m2/repo/org/jclouds/provider/rackspace-cloudservers-us/1.5.8/rackspace-cloudservers-us-1.5.8.pom -DoutputDirectory=/path/to/target/dir/don't/use/.

As pointed out by Everett Toews, you can use additional options of copy:dependencies to further refine what's downloaded, e.g. by adding -DexcludeTypes=test-jar to filter out the test JARs.