使用maven-shade-plugin时出现多余的警告 [英] Superfluous warnings when using maven-shade-plugin

查看:313
本文介绍了使用maven-shade-plugin时出现多余的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 maven-shade-plugin 作为一个简单的maven项目,该插件成功地将所有依赖项包含在最终的阴影jar中。这个过程每次都运行良好,并且正好产生我需要的东西。

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.

当运行第一时间(在清洁),插件很安静,输出很少。但是,重新运行时(上一次构建中没有 clean ),会有很多警告消息,例如;

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.

我的问题很简单:如何在不必先运行 clean 的情况下安全地解决或抑制这些警告消息?

My question is simple: how can I safely workaround or suppress these warning messages without having to run a clean first?

注意:可能的解决方案是转移到 maven-assembly -plugin ,但我不愿意,因为 maven-shade-plugin 的配置非常简单。

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.

推荐答案

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

This is because it is shading the files into an already shaded jar.

第一次在清理后运行包时,它将创建jar。
第二次运行它然后它就不会因为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.

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

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

这篇关于使用maven-shade-plugin时出现多余的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆