使用 maven-shade-plugin 时出现多余的警告

发布于 2024-12-27 17:34:25 字数 571 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肩上的翅膀 2025-01-03 17:34:25

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

第一次在 clean 后运行 package 时,它​​将创建 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>

这对我有用。要么就是这样,要么只是进行全新安装

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文