I must be missing something. I have searched and searched, and played and tinkered, and I still can't figure out how to do the following with Maven:
I would like to download an artifact and all its dependencies (and transitive dependencies), from our internal Nexus server, into a user-specified location. The idea here is to allow the person who is deploying the solution into production a way that they can easily get all the jar files they need in one place.
There is dependency:get, and this is close-but-no-cigar. With dependency:get, all the artifacts are downloaded into the local mvn repository, under directories according to each artifact's groupId and artifactId. This is NOT what I want, because then you have to trudge around all those directories to get at the jars. I want all the files downloaded to one directory so that they are in one place.
Then there is dependency:copy-dependencies. This again does almost what I want; it copies all of an artifact's deps into target/dependency. The two problems with this are 1) You need to have a pom.xml; you can't specify arbitrary coordinates like you can with dependency:get, and 2) dependency:copy-dependencies does't copy the main artifact itself into target/dependencies.
There must be a better way to do this, but I can't figure out where else to look for a solution. To summarize, I want to be able to given someone a set of maven coordinates (groupId:artifactId:version) and our internal Nexus URL, and have them download everything with one command into a directory of their choosing.
Use the maven assembly plugin to package an additional "jar with dependencies" into a ZIP file that includes everything.
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<!-- TODO: a jarjar format would be better -->
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
Then the user can just request <type>zip</type>
, in addition to the regular 'maven coordinates' to get a zip file with all the dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With