Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download an artifact with its dependencies to a specified directory - without pom.xml - using Maven?

Tags:

java

maven

What I need to do is to download an artifact from my internal repository (currently Nexus) with all its dependencies, to a specified directory. And that without actually downloading the source code (and using its pom.xml): I need to just run a plain maven command from the shell and access the binaries in my repository.

I don't need to download the dependencies to my local repository (the behaviour of the dependency:get / dependency:copy plugins), I want the artifact AND all of its dependencies copied to a specified directory.

Something like this:

mvn super-downloader:download-everything -Dartifact=my.group:myArtifact:version -Ddirectory=.

What I've tried:

dependency:get and dependency:copy plugins copy the dependencies to my local repository (under ~/.m2) which is not what I want.

dependency:copy-dependencies requires a maven project. I need to run the command without a pom.xml.

com.googlecode.maven-download-plugin:maven-download-plugin:artifact plugin should work with -DdependencyDepth=<some high value>, but it fails trying to resolve a dependency to xerces:xerces-impl:2.6.2. I manually uploaded it to my Nexus, but then it failed trying to find xml-apis:xml-apis:2.6.2, which doesn't exist.

So, any ideas?

Thanks.

like image 227
Gilberto Torrezan Avatar asked Oct 02 '22 12:10

Gilberto Torrezan


2 Answers

Inspired by the this answer, I created a simple bash script to solve the problem:

#mvn-copy.sh
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dmdep.useBaseVersion=true -DoutputDirectory=. -Dartifact=$1:$2:$3
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dmdep.stripVersion=true  -DoutputDirectory=. -Dartifact=$1:$2:$3:pom
mvn -f $2.pom org.apache.maven.plugins:maven-dependency-plugin:2.8:copy-dependencies -DoutputDirectory=lib

To use it, just type ./mvn-copy.sh <groupId> <artifactId> <version>. It will download the main jar at the current directory, and then all dependencies into a lib folder.

Not the best solution, not the most beautiful one, and not quite what I wanted, but it solved the problem and saved the day.

like image 111
Gilberto Torrezan Avatar answered Oct 06 '22 05:10

Gilberto Torrezan


You're asking for https://jira.codehaus.org/browse/MDEP-322 which seems a fair request

like image 34
Robert Scholte Avatar answered Oct 06 '22 04:10

Robert Scholte