【问题标题】:Maven not failing on compiler warningsMaven 在编译器警告上没有失败
【发布时间】:2015-07-24 16:05:14
【问题描述】:

我有一个 maven 项目,当我进入生产阶段时,我希望构建在任何编译器警告时都失败。

我浏览了网络并在this SO post 的指导下配置了我的 pom.xml

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <compilerArgument>-Werror</compilerArgument>
        <compilerArgument>-Xlint</compilerArgument>
        <fork>true</fork>
    </configuration>
</plugin>

在我的项目中,我删除了一些参数化以创建未经检查的演员表:

return ((Map<String, Object>)getProperty("settings", Map.class).get("aSetting");

eclipse 和 maven 都将其正确识别为编译器警告。然而,尽管警告出现在 maven 的编译日志中,项目仍然编译并返回成功:

sysadmin@ubunyu:~/workspace/project$ mvn compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building My Project 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.4:compile (default-compile) @ project ---
[INFO] Compiling 13 source files to /home/sysadmin/workspace/project/target/classes
[WARNING] /home/sysadmin/workspace/project/src/main/java/project/package/MyClass.java:[305,69] [unchecked] unchecked cast
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.753s
[INFO] Finished at: Fri Jul 24 11:50:03 EDT 2015
[INFO] Final Memory: 8M/161M
[INFO] ------------------------------------------------------------------------
----------------

我在编译器配置中尝试了 -Werror、-Xlint、fork、showWarning 和 showDepreciation 的不同组合,但没有任何结果如我预期的那样产生编译错误。

【问题讨论】:

    标签: java maven compilation


    【解决方案1】:

    使用

    <compilerArguments>
        <Xlint/>
        <Xlint>cast</Xlint>
    </compilerArguments>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多