I am using maven-shade-plugin for a simple maven project, the plugin successfully includes all the dependencies into a final "shaded" jar. The process works well every time and produces exactly what I need.
When run the "first" time (after a clean
), the plugin is quiet and produces very little output. However, when re-run (without a clean
from the last build), there are lots of warning messages such as this;
[WARNING] We have a duplicate package/a/b/foo.class
[WARNING] We have a duplicate package/c/d/bar.class
This are warning messages only and the final artifact works fine.
My question is simple: how can I safely workaround or suppress these warning messages without having to run a clean
first?
note: A possible solution would be to move to the maven-assembly-plugin, but I would prefer not to because the configuration for maven-shade-plugin is very nice and simple.
We can use the shade plugin in maven to obtain the single jar file also called as uber/fat jar file that is self-sufficient and can be run independently as it contains all the dependencies and project code inside it. This can be done by simply adding the plugin tag with shade plugin related information as shown in the above example.
Apache Maven Shade Plugin. This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies. The Shade Plugin has a single goal: shade:shade is bound to the package phase and is used to create a shaded jar.
There are many plugins available for maven projects. The main aim of the plugins is to provide the capability to form the package of the artifacts in the maven project and its dependencies into an uber or fat jar and rename certain packages. Uber is a german word that stands for above which means it is one level up, unlike the other normal jars.
This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies. The Shade Plugin has a single goal: shade:shade is bound to the package phase and is used to create a shaded jar.
This is because it is shading the files into an already shaded jar.
The first time you run package after a clean then it will create the jar. The second time you run it then it doesn't bother as the jar already exists.
From the shade plugins perspective it doesn't know that this has already been shaded so it just tries to add the classes again.
We can force maven to create the jar everytime by configuring the jar plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<forceCreation>true</forceCreation>
</configuration>
</plugin>
And this works for me. Either that or just do a clean install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With