Friday, April 28, 2017

Excluding Property Files from Jar File : Maven Shade Plugin

Recently, i wanted to create a single Jar file with all the dependencies while the property files are excluded which are coming from the project. But the property files which are coming from dependencies should be preserved. My idea was to externalize property file so that someone can edit them without going inside Jar.

I tried several options.

Resources plugin perfectly work for the need. But it excludes the property files even when i run the project from the IDE (Eclipse/NetBeans)

I tried jar-with-dependencies pre-defined assembly descriptor with few customization. I used exclusion in unpackOptions. But it excludes property files which are coming from all the dependent modules.

Finally i found the working solution. It was Maven Shade Plugin

Following is example pom.xml. There you can see how i have used Maven Shade Plugin with property file excluding configurations. Shade plugin can be use to filter any file file from any dependent module conveniently.
Since i wanted an executable Jar i have specially used ManifestResourceTransformer in the Shade configurations.