Unpacking a kit for inclusion in a Java library
The first time I came to do this I was new to maven and I didn’t know about the maven-dependency-plugin, so I had a hard time keeping a handle on the downloaded kit. Well, I’m back, and this time I mean business.
I’ve listed the plugins I used in something like sequential order:
maven-dependency-plugin
The maven-dependency-plugin is used to download a kit which contains
a bunch of templates used in my artifact (which happens to be a Java
library). I chose to bind this to the process-resources
phase because
nobody told me not to, but really it could have gone anywhere before the
antrun execution.
{% highlight xml %} org.apache.maven.plugins maven-dependency-plugin 2.4 copy-dependency process-resources unpack
<groupId>com.mycompany</groupId>
<artifactId>some-artifact</artifactId>
<type>zip</type>
<classifier>some-classifier</classifier>
<version>some-version</version>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/template-kit</outputDirectory>
<excludes>**/*.inventory</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
maven-antrun-plugin
I used antrun to unpack the kit to a staging directory. The working tree
in the staging directory is organised in the same way as in the jar. The
property ${project.build.directory}
is globally set and holds the
location of the target/
directory.
{% highlight xml %} maven-antrun-plugin template-unpack prepare-package run
<copy todir="${staging}">
<fileset dir="${project.build.directory}/template-kit/">
<include name="**/some/files/to/include/*" />
</fileset>
<flattenmapper />
</copy>
</tasks>
</configuration>
</execution>
</executions>
maven-assembly-plugin
Finally the assembly plugin is is used in conjunction with the assembly
descriptor (kit.xml
) to jar everything up.
{% highlight xml %} maven-assembly-plugin make-assembly package single false target/classes/META-INF/MANIFEST.MF src/main/assembly/kit.xml {% endhighlight %}
The kit.xml
for all the magic looks like this:
{% highlight xml %} distribution jar false target/staging/ / templates//* /*.java false {% endhighlight %}
Here’s the documentation for the maven-dependency-plugin. It’s got some jolly good examples.