2

I have a maven project, and as I move to production I want the build to fail on any compiler warnings.

I have looked through the web and configured my pom.xml with guidance from this SO post

<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>

In my project, I removed some parameterization to create an unchecked cast:

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

Which is correctly identified by both eclipse and maven as a compiler warning. However, despite the warning showing up in maven's compile log, the project still compiles and returns success:

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] ------------------------------------------------------------------------
----------------

I've tried different combinations of -Werror, -Xlint, fork, showWarning, and showDepreciation in the compiler configuration, but nothing is producing an compilation error as I'd expect.

1 Answers1

0

Use

<compilerArguments>
    <Xlint/>
    <Xlint>cast</Xlint>
</compilerArguments>
talex
  • 17,973
  • 3
  • 29
  • 66