maven – give me my files!
Every time I work with Maven I like a ton of things about it and get really annoyed by a few. Today I was faced with an issue for the second time: I have a Maven project that produces a .jar as its artifact and I want to have a build goal produce a directory with that .jar AND copies of the .jar’s that it depends on. Without this, my only means of distributing my code is if the recipient uses Maven also. I partially solved this a few months ago and today found a more complete solution. Its not complete (the .jars end up in a horribly ugly directory under the target folder) but it works … and that’s what matters.
The solutions uses the Maven Assembly plugin. First, I needed a custom assembly configuration which I put in a file called assembly.xml in the root of my project:
<?xml version="1.0" encoding="UTF-8"?> <assembly> <id>bin</id> <formats> <format>dir</format> </formats> <dependencySets> <dependencySet> <unpack>false</unpack> </dependencySet> </dependencySets> </assembly>
This file describes how the plugin should assembly my project; moving all of my dependencies, unpacked, into a single folder. There is a huge assortment of options available ranging from include/exclude parameters to how/where to move files. I am still slowly working my way through the reference doc.
Second, I modified my pom.xml to configure the Assembly plugin:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> </configuration> </plugin>
Finally, a call to mvn assembly:directory will compile your project, run the tests, package your project and produce the desired folder. Done.

leave a comment