2

Summary of my issue: in a multi-module project, one of the module has a dependency to another module. When building an uber jar of this module with the maven-shade-plugin, all its dependencies are correctly included, but not the dependencies of the other module.


I have a multi-module project, with following architecture:

pom.xml (parent pom)
--module_1
----pom.xml
--module_2
----pom.xml

module_2 has a dependency to module_1, declared in its pom.xml:

<groupId>${project.groupId}</groupId>
<artifactId>module_1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>

I want to build an uber jar of module_2, and I use the maven-shade-plugin, with the following declaration:

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

This results in an uber jar:

  • including all dependencies of module_2
  • including the jar of module_1
  • not including dependencies of module_1

Is there a way to specify to include all dependencies of module_1 as well?

A solution I found is to use the maven-shade-plugin to buid an uber jar of module_1 as well. As this jar is included in the uber jar of module_2, then it works. But I'd like to avoid this solution, to be able to release a simple jar file of module_1, not including its dependencies.

And I want to use the maven-shade-plugin rather than the maven-assembly-plugin (for its better control over files included in final jar)


Following request for more details by @user2321368

maven version: Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)

module_1's pom.xml where I include its dependencies: (scopes and versions are declared in the parent pom in the dependency management section)

<dependencies>

  <dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>other_module_I_havent_mention</artifactId>
  </dependency>

  <dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>other_module_I_havent_mention</artifactId>
    <type>test-jar</type>
  </dependency>

  <dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
  </dependency>

  <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
  </dependency>

  ...
</dependencies>
FBB
  • 1,414
  • 2
  • 17
  • 29
  • I would strongly suggest you to use `maven-assembly-plugin`, you can have control of `classpath` if that is your concern for not using it – jmj Jul 10 '14 at 16:54
  • Are you certain this is the behavior you are seeing i.e. have you extracted the contents of the produced uber-jar file? – dan.m was user2321368 Jul 10 '14 at 17:02
  • The reason I ask is that what you desire is the expected behavior of the plugin, and something that I use every day. – dan.m was user2321368 Jul 10 '14 at 17:13
  • @user2321368: yep; i have extracted the content of the uber-ja to make sure. – FBB Jul 10 '14 at 20:57
  • @JigarJoshi: no, my concern is configuration files present in dependencies that override my own configuration files. Using the maven-shade-plugin I have control on which file overrides which file. – FBB Jul 10 '14 at 20:58
  • You will still have those configuration file packed inside your assembly (may be inside jar of jar) – jmj Jul 10 '14 at 21:02
  • What version of maven are you using? Can you include the part of module_1's pom.xml where you include its dependencies. – dan.m was user2321368 Jul 10 '14 at 22:36
  • @user2321368 : message updated with the details you asked for. – FBB Jul 12 '14 at 11:43
  • Did you find a solution to your problem in the last 3 years ? – Jay Zus Sep 13 '17 at 11:34

0 Answers0