5

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.

Gilberto Torrezan
  • 5,113
  • 4
  • 31
  • 50
  • See: http://stackoverflow.com/questions/15450383/using-maven-to-download-dependencies-to-a-directory-on-the-command-line/15456621#15456621 – Mark O'Connor Feb 24 '14 at 19:46

2 Answers2

3

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.

Community
  • 1
  • 1
Gilberto Torrezan
  • 5,113
  • 4
  • 31
  • 50
1

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

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44