简体   繁体   中英

How to download an artifact with its dependencies to a specified directory - without pom.xml - using 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.

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.

您正在请求https://jira.codehaus.org/browse/MDEP-322 ,这似乎是一个公平的要求

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM