Skip to content
Advertisement

How to configure Maven shade plugin in a multi-module project?

I have been trying to get jar using Maven Shade Plugin, but I still don’t get a success.

This is my project structure:

JavaScript

Module1 (pom.xml):

JavaScript

Module2 (pom.xml):

JavaScript

MainModule (pom.xml):

JavaScript

According this code I get 2 jar-files (Module1-version.jar and Module2-version.jar). But it is not what I want. I wish to get 1 jar file (MainModule-version.jar), which would contain the other (Module1 and Module2).

Why doesn’t this Shade Plugin work?

Advertisement

Answer

You MainModule is not supposed to produce a jar file. It can produce only… pom files. It contains configuration shared across all it child modules. This is why the shade plugin is called against each modules.

Instead, create a third module. Let’s call it FinalModule. This module is a child of MainModule. Move the whole <build> node from MainModule pom.xml to FinalModule pom.xml.

File structure:

   MainModule
      -FinalModule
        -src
        -pom.xml
      -Module1
        -src
        -pom.xml
      -Module2
        -src
        -pom.xml
      -pom.xml

The FinalModule pom.xml looks like this:

FinalModule (pom.xml)

JavaScript

In the end, you should get something like this:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement