I have used Apache Maven Shade Plugin to create fat jar (the jar which includes all classes from all dependencies). My current project folder structure looks something like this,
> Parent Module (packaging pom)
> Module 1 (packaging jar)
> Own classes
> Dependency-1
> Dependency-2
> Module 2 (packaging jar)
> Own classes
> Module 1 (I want here only classes written in module-1, not any transitive dependencies)
> Dependency-1
> Dependency-2
> Dependency-3
The pom.xml
snap-shot from Parent Module,
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>common-shade</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
The pom.xml
snap-shot from Module-1 & Module-2 looks like this,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>common-shade</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
The dependency declared for Module-1 in Module-2 pom looks like this,
<dependency>
<groupId>my.com.groupId</groupId>
<artifactId>my.artifactId</artifactId>
<version>1.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
NOTE : Currently, if I see my dependencies using mvn dependency:tree -Dverbose
, then it's showing as expected, but shade-plugin
is not excluding it.
Problem : The module-1 & module-2 have some same dependencies with different versions. If I skip/disable shade-plugin declared in Module-1, then I can run Module-2 with no issues, but if I don't disable it, then the fat jar created by Module-2 includes some classes from jars with Module-1 versions, so my Module-2 stops running.
UPDATE :
I use fat jar to run individual modules like this,
java -cp module.jar com.mycom.Main
Any help please?