java - 如何让 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>

但没有喜悦。现在有任何想法来解决 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不需要启用,即使 文档另有说明。

https://stackoverflow.com/questions/9192613/

相关文章:

java - 如果未激活另一个配置文件,则激活 Maven 配置文件

.net - MSBuild - 如何从预先编写的命令行命令构建 .NET 解决方案文件(在 XML

build - CodeBuild 执行在构建失败后继续执行,而不是停止

build - EA 在 Java 版本中代表什么?

java - java文件中的Maven版本号

c# - 是否有 Visual Studio 构建探查器?

c# - 错误构建 VSTS : ## [error] Error: Unable to locat

java - 有没有使用 maven 运行可执行 jar 的好方法?

build - CMake将非编译文件导入构建目录

java - 在 Maven 测试阶段禁用 Log4J 日志