views:

131

answers:

1

I have a scenario where-in I need to create an uber jar of a multi module maven project including all modules and their dependencies. I tried using maven shade plugin. but it seems to work only when I use it at the module level. If I add the plugin entry in parent pom then the build breaks (it tries to shade the parent pom)

 [INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing null with C:\Projects\foo.bar\target\foobar-0.0.1-SNAPSHOT-shaded.pom
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error creating shaded jar: null

It does seem to make sense since the <packaging> for the parent maven project is pom. But there should be some way to create an uber jar for a multi module project... Any ideas people???

+1  A: 

You should not be using your parent project's POM file to attempt shading; you should be using a separate aggregator project for this. Parent maven projects are used for inheritance while aggregator projects are used to perform aggregate functions over a group of sub-projects; like shading their JARs together into a uber jar. This project would simply be a pom file at the root directory of your project (the same level as all the sub-modules' folders) which references the sub-projects and has the shade plugin configuration. Make sure the packaing specified for this pom is JAR.

Here is the documentation explaining POM relationships and difference between Aggregation and Inheritance.

Gweebz