使用 maven-shade-plugin 时出现多余的警告
我正在使用 maven-shade-plugin 进行一个简单的 Maven 项目,该插件成功地将所有依赖项包含到最终的“阴影”jar 中。这个过程每次都很顺利,并且生产出的正是我所需要的。
当“第一次”运行时(在clean
之后),插件很安静并且产生很少的输出。然而,当重新运行时(没有上次构建的clean
),会出现很多警告消息,例如:
[WARNING] We have a duplicate package/a/b/foo.class
[WARNING] We have a duplicate package/c/d/bar.class
这只是警告消息,最终的工件工作正常。
我的问题很简单:如何安全地解决或抑制这些警告消息,而不必先运行 clean
?
注意: 一个可能的解决方案是移至 maven-assemble-plugin,但我不想这样做,因为 maven-shade-plugin< 的配置/em> 非常好而且简单。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为它将文件着色到已经着色的 jar 中。
第一次在 clean 后运行 package 时,它将创建 jar。
第二次运行它时,它不会打扰,因为 jar 已经存在。
从阴影插件的角度来看,它不知道它已经被着色,所以它只是尝试再次添加类。
我们可以通过配置 jar 插件强制 maven 每次创建 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:
And this works for me. Either that or just do a clean install