15

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.

4

1 回答 1

17

这是因为它将文件着色到已经着色的 jar 中。

清理后第一次运行包时,它将创建 jar。第二次运行它时它不会打扰,因为 jar 已经存在。

从阴影插件的角度来看,它不知道这已经被着色,所以它只是尝试再次添加类。

我们可以通过配置jar插件来强制maven每次都创建jar:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <version>2.4</version>
   <configuration>
     <forceCreation>true</forceCreation>
   </configuration>
</plugin>

这对我有用。要么做一个干净的安装

于 2012-06-13T12:48:36.537 回答