Superfluous warnings when using maven-shade-plugin

谁说我不能喝 提交于 2019-12-21 07:16:13

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/8880361/superfluous-warnings-when-using-maven-shade-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!