我正在尝试:
<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>
但没有喜悦。现在有任何想法来解决 this blog post 中建议的此类错误。 ?
最佳答案
2015 年更新,使用 Maven 3.3 和 Java 8。
这是一个最小的编译器配置,它可以启用所有警告并使 只要出现警告,构建就会失败。
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
注意事项:
-
<showWarnings>true</showWarnings>
是必须的。由于未知的原因,Maven 默认使用-nowarn
主动抑制警告。标志,所以-Xlint
和-Werror
标志将被忽略。 -
showDeprecation
不需要启用,因为-Xlint:all
已发出弃用警告。 - 实验表明
fork
不需要启用,即使 文档另有说明。
关于java - 如何让 Java maven 构建因编译器警告而失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9192613/