我有一个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的不同组合,但没有任何东西像我期望的那样产生编译错误。
答案 0 :(得分:0)
使用
<compilerArguments>
<Xlint/>
<Xlint>cast</Xlint>
</compilerArguments>