Bundling project dependencies with the shade plugin

Have you ever struggled with the mass of .jar files that you can find in a directory of Java libraries? You have no idea what version each of them is and what its dependencies are. You want to put your own application jar in there, but you know that will mean needing to get hold of 20 other jar files to deal with its dependencies.

I certainly have trouble with this. I use the Drools Guvnor web application to manage business rules, but this sometimes requires that I place my own libraries in that web application’s lib directory. Some of these libraries are actually minimal Spring applications which need to do data access and invoke web services. This means that each of them does require multiple additional Jar files. It becomes difficult to keep track of what libraries I have added to that directory and what I need to add.

However I have come across a decent way of dealing with this problem. The shade plugin enables me to build a single .jar file containing all dependencies for an application. This way, I’m able to ensure that all the dependencies I tested against in my build are definitely the ones that have been deployed.

The following is a basic example of configuring the shade plugin in your pom.xml:

I also find it particularly handy for FitNesse where I’m able to run a quick script to download the latest version of an artifact from a repository, and I know that what I’m getting includes all the dependencies I need. If a dependency version changes, or is added, I don’t need to alter my deployment script.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s