We need to build a jar, using Maven, in a way that all its dependencies are included, but also that all those dependencies are renamed (relocated).
Let's say our own packages all start with com.mycompagny.projectx.*
". We want the project dependencies to have their package renamed to starts with "embedded
", but not our own classes.
Using maven-shade-plugin for example, I'm not able to achieve this :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<artifactSet>
<includes>
<include>*.*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>*</pattern>
<shadedPattern>embedded.</shadedPattern>
<excludes>
<exclude>com.mycompagny.projectx.*</exclude>
</excludes>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
Here <pattern>*</pattern>
is not valid. Also, if I use <pattern></pattern>
(empty string), then everything is relocated to the "embedded" package, even the resources (the "META-INF" directory too)! Of course we want the resources to stay at the root of the jar.
I guess we could create multiple <relocation>
elements, one for each package of the dependencies, but that would be a lot of work : <relocation>com</relocation>
, <relocation>net</relocation>
, <relocation>javax</relocation>
, etc.
Any idea on how to easily relocate all dependencies inside the uber jar, without touching our own classes, resources and the "META-INF" directory?