How do I get a Java maven build to fail for compiler warnings?

后端 未结 6 556
暖寄归人
暖寄归人 2020-12-10 11:01

I am trying:

        
            org.apache.maven.plugins
            maven-compiler-plugin&l         


        
6条回答
  •  余生分开走
    2020-12-10 11:44

    Update for the year 2015, using Maven 3.3 and Java 8.

    Here's a minimal compiler configuration that enables all warnings and makes the build fail whenever warnings occur.

    
        
            maven-compiler-plugin
            3.3
            
                1.8
                1.8
                true
                
                    -Xlint:all
                    -Werror
                
            
        
    
    

    Bits of note:

    • true is required. For reasons unknown, Maven by default actively suppresses warnings with the -nowarn flag, so the -Xlint and -Werror flags would be ignored.
    • showDeprecation doesn't need to be enabled because -Xlint:all already emits deprecation warnings.
    • Experimentation shows that fork doesn't need to be enabled, even though the documentation says otherwise.

提交回复
热议问题