3

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.

Community
  • 1
  • 1
Ivan Stoyanov
  • 5,412
  • 12
  • 55
  • 71
  • How did you define the maven-shade-plugin settings? without seeing what you set up it's hard to diagnose. – Tschallacka Apr 11 '16 at 12:48
  • @MichaelDibbets please see the EDIT section for the config. – Ivan Stoyanov Apr 11 '16 at 12:53
  • https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html is there a reason you didn't define ? – Tschallacka Apr 11 '16 at 12:56
  • It's unclear what you want to do but my guess is that you want to create a dedicated module under `moduleD` and `moduleE` that will be responsible for creating the uberjar. So you'll have one module `moduleD-uber` under `moduleD` that has dependencies on `moduleA`, `moduleB`, `moduleC`. – Tunaki Apr 11 '16 at 12:57
  • @MichaelDibbets I didn't define , because I want to include all dependencies. I probably have to define for the Log4J dependency as it is used in multiple modules. – Ivan Stoyanov Apr 11 '16 at 12:59
  • @Tunaki so I have to create a separate module (`moduleD-uber`) that will create my uber jar? Shouldn't I be able to crate an uber jar from `moduleD`. Creating a new module just for this seems redundant. – Ivan Stoyanov Apr 11 '16 at 13:01
  • No, because it is of packaging `pom`, so it won't work. I think. – Tunaki Apr 11 '16 at 13:02
  • @Tunaki can you give me more info. It is the first time that I have heard something like this. – Ivan Stoyanov Apr 11 '16 at 13:07
  • The question is, what exactly do you want to do? It's still unclear to me. `moduleD` is a parent `pom` project so it doesn't really make sense to make an uberjar of it. – Tunaki Apr 11 '16 at 13:10
  • `moduleD` is a console java application with a `main` method. The idea is that the application depends on other modules that I use as libraries, in order to reuse the code in multiple modules. I want to create a uber jar for `moduleD`, that contains all of `moduleD` dependencies including the module itself and use the uber jar for deployment. – Ivan Stoyanov Apr 11 '16 at 13:15
  • How can `moduleD` be a Java application if it serves as a parent POM for ``? – Tunaki Apr 11 '16 at 13:25
  • Sorry it is my mistake. There are no parent poms. Each module have their own `pom.xml` file. – Ivan Stoyanov Apr 11 '16 at 13:26
  • 2
    @IvanStoyanov, see logback-android's [pom-uber.xml](https://github.com/tony19/logback-android/blob/d013e41/pom-uber.xml), which creates an uber jar of its submodule projects. –  Apr 11 '16 at 13:46

1 Answers1

2

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.

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • It is still failing. My guess is that it can't find the .jar files of the other modules. – Ivan Stoyanov Apr 11 '16 at 13:05
  • Have you tried making a seperate project, that includes all these projects, and that compiles it into an uberjar? To prevent http://mythologian.net/wp-content/uploads/2013/10/Ouroboros-dragon-serpent-snake-symbol.jpg from happening somehow, that it keeps looping. – Tschallacka Apr 11 '16 at 13:07
  • No I haven't. So far I have tried to create a uber jar for `moduleC` and it is failing. I haven't tried `moduleD` as I guess that if `muduleC` that is one of the dependencies of `moduleD` is failing, `moduleD` will fail as well. Are you suggesting that I should create a new module dependent only on `moduleD` and create a uber jar from it? How would this work? – Ivan Stoyanov Apr 11 '16 at 13:11
  • See the new module as a complete package dependent on all other packages, it uses them and them compiles them all together into one well defined package. Usually in cases like these, I find it better to explicitly list what I need to be included a and excluded. Might seem tedious, but at least you're not suprised by unexpected things. – Tschallacka Apr 11 '16 at 13:14