如何让 Java Maven 构建因编译器警告而失败?
我正在努力:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Werror</compilerArgument>
<fork>true</fork>
</configuration>
</plugin>
但没有快乐。现在有任何关于此类错误的想法,如 这篇博文中所建议的?
I am trying:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Werror</compilerArgument>
<fork>true</fork>
</configuration>
</plugin>
but with no joy. Any ideas now to get medieval on such errors as suggested at this blog post?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
2015 年更新,使用 Maven 3.3 和 Java 8。
这是一个最小的编译器配置,可以启用所有警告并使得
每当出现警告时构建都会失败。
值得注意的是:
true
是必需的。由于未知原因,Maven 默认情况下会主动抑制带有-nowarn
标志的警告,因此-Xlint
和-Werror
标志将被忽略。showDeprecation
,因为-Xlint:all
已经发出弃用警告。fork
,即使文档另有说明。
Update for the year 2015, using Maven 3.3 and Java 8.
Here's a minimal compiler configuration that enables all warnings and makes
the build fail whenever warnings occur.
Bits of note:
<showWarnings>true</showWarnings>
is required. For reasons unknown, Maven by default actively suppresses warnings with the-nowarn
flag, so the-Xlint
and-Werror
flags would be ignored.showDeprecation
doesn't need to be enabled because-Xlint:all
already emits deprecation warnings.fork
doesn't need to be enabled, even though thedocumentation says otherwise.
maven-compiler-plugin
3.6.0 中的新增功能:failOnWarning
标志。这对我有用:请注意,我必须排除
processing
lint,否则自动事项的注释会破坏构建,并出现神秘的“符号未找到”错误。New in
maven-compiler-plugin
3.6.0: thefailOnWarning
flag. This worked for me:Note that I had to exclude the
processing
lint or otherwise auto-matter's annotations would break the build with cryptic "symbol not found" errors.2020年的更新,我使用的是Spring Boot 2.2.5。以下配置可以在出现警告、错误时停止
mvn install
。An update on 2020, I am using Spring Boot 2.2.5. The following config can stop the
mvn install
when warning, error happen.编辑:这个答案已经过时,但我无法删除它,因为它是当时接受的答案。
这是 Maven 的错误,请参阅: https://issues.apache.org/jira/browse /MCOMPILER-120 它已在 Maven-compiler-plugin 2.4 中修复,但我认为尚未发布。不幸的是,标签也不起作用。
EDIT: This answer is outdated however I can't delete it as it was an accepted answer at the time.
This a bug with Maven see: https://issues.apache.org/jira/browse/MCOMPILER-120 it's been fixed in 2.4 of the Maven-compiler-plugin but I don't believe that's been released yet. tag won't work either unfortunately.
有另一种形式也许可以尝试一下?请注意末尾的 s
There is an alternate form perhaps give it a try? Note the s on the end of
<compilerArguments>
通过使用 此评论 在 针对 maven 编译器插件打开 jira 问题,构建可能因编译器警告而失败。
这对我有用:
By using the workaround in this comment in the open jira issue for maven compiler plugin, the build can be failed for compiler warning.
This works for me:
当我正在寻找一个可行的解决方案来使我的 Maven 构建因编译器警告而失败时,我到达了这篇文章
有关更多详细说明,请参阅下面的链接
将警告视为错误
I arrived at this post when I was looking for a working solution to fail my maven builds for compiler warnings
For more explanation in detail please refer the link below
Treat warnings As Errors