Ivan Stoyanov
Ivan Stoyanov

Reputation: 5482

How to build a Uber jar with dependencies from multiple modules

I have set up a multiple modules project in IntelliJ. My modules structure looks like this:

Project (no pom.xml file)
|
|--moduleA
|    |
|
|--moduleB
|    |-Log4J
|    |-Jackson
|
|--moduleC
|    |-moduleA
|    |-moduleB
|    |-Log4J
|
|--moduleD
|    |-moduleC
|    |-moduleA
|    |-moduleB
|    |-Log4J
|
|--moduleE
|    |-moduleA
|    |-moduleB
|    |-moduleC
|    |-Log4J

moduleC depends on moduleA and moduleB, and moduleD depends on moduleA, moduleB and moduleC. The same goes for moduleE.

I want to create two Uber jars. One for moduleD and one for moduleE, each of them containing the module's dependencies, including module A, B and C.

I am using Maven 3 to manage my dependencies and the maven-shade-plugin to create the Uber jar.

I have added the necessary dependencies in the pom.xml files like this:

<dependency>
  <groupId>com.modules</groupId>
  <artifactId>moduleA</artifactId>
  <version>1.0</version>
</dependency>

And I have added the maven-shade-plugin to the pom.xml files of each module. So far I am able to build an uber jar for moduleA and moduleB, but when I try moduleC I get the following error:

[WARNING] The POM for com.modules:moduleA:jar:1.0 is missing, no dependency information available
[WARNING] The POM for com.modules:moduleB:jar:1.0 is missing, no dependency information available

How can I resolve this?

If I build and run the modules trough IntelliJ everything works. Also I was able to build an uber jar by configuring an IntellJ artifact.

How can I configure Maven to do this? I need it because I want to use an uber jar for production and I am trying to setup Jenkins to build the solution after a commit.

I have red the following post: How to create self-containing (standalone) jar of each modules of a multi-module maven project but I was not able to make it work.


EDIT:

This is the maven-shade-plugin settings in moduleA and moduleB

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

This is the maven-shade-plugin in moduleC:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
            </execution>
        </executions>
    </plugin>

As you can see I am using the default configuration.

Upvotes: 3

Views: 2850

Answers (1)

Tschallacka
Tschallacka

Reputation: 28722

Try adding

<includes>
  <include>**</include>
</includes>

at the same place where you define your excludes.

The only occurences of <filter> I can find is in combination with the include and exclude filters.

Don't hold me on it, but that's my guess why your build fails.

Upvotes: 2

Related Questions