Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I need to download all transitive dependencies of a project to a directory on the command line without having a pom.xml file or other script. Ideally I would be able to do this with one or two commands. From what I can tell, this is at least a 2 step process with mvn.

  1. Download dependencies to the local repository
  2. Copy the dependencies to the lib directory

To get the dependencies I run

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

Which works great. Unfortunately the dest param doesn't help me as it won't put all transitive dependencies in the dest.

So now I need to copy that JAR file and all of its transitive dependencies into my lib directory. I know this part has been asked many time on StackOverflow but nothing has worked for my yet. I've tried the following.

$ mvn dependency:copy-dependencies ... [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:copy-dependencies (default-cli): Goal requires a project to execute but there is no POM in this directory 

and

$ mvn dependency:copy ... [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:copy (default-cli): Goal requires a project to execute but there is no POM in this directory 

From reading the documentation and other answers here on StackOverflow for copy-dependencies and copy I thought I would be able to use them from the command line without a pom.xml but mvn seems to need one. My Maven version is Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600).

Can anyone give me an example of copying transitive dependencies using mvn without a pom.xml?

Is there a better way to do what I'm trying accomplish here?

like image 937
Everett Toews Avatar asked Mar 16 '13 14:03

Everett Toews


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 .

How can I download all the dependency files?

If you want do download them all, you can try using mvn dependency:copy-dependencies . Then, you'll find all project dependencies in target/dependencies directory of your project. This also includes transitive dependencies. To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin .

Where does POM xml download dependencies?

If you build your project using the minimal POM, it would inherit the repositories configuration in the Super POM. Therefore when Maven sees the dependencies in the minimal POM, it would know that these dependencies will be downloaded from https://repo.maven.apache.org/maven2 which was specified in the Super POM.


1 Answers

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 
like image 76
Mark O'Connor Avatar answered Oct 14 '22 14:10

Mark O'Connor