强制maven无法修复非空的违规行为
我有下面的简单代码,用于测试带有maven的findbugs NonNull注释。
我执行“mvn clean install site”,我得到一个目录target / site / css和target / site / images,但仅此而已。 我期待得到一个报告,说println(null)违反了NonNull条件。
要获得该报告,我需要做什么?
另外,如果存在NonNull违规,有没有办法阻止“mvn clean install”成功?
注意:我知道我可以通过Sonar获得此类报告; 但是,如果存在此类错误,我希望“mvn clean install”失败,之后无需使用可选的Sonar工具。
的src /主/爪哇/测试/ Hello.java
package test; import edu.umd.cs.findbugs.annotations.NonNull; public class Hello { static public void print(@NonNull Object value) { System.out.println("value: " + value.toString()); } static public void main(String[] args) { if (args.length > 0) { print(args[0]); } else { print(null); } } }
和pom.xml文件:
4.0.0 hello hello 1.0 net.sourceforge.findbugs annotations 1.3.2 net.sourceforge.findbugs jsr305 1.3.7 org.codehaus.mojo findbugs-maven-plugin 2.5.2
—
更新,解决方案
解决方案,基于Augusto的答案:将其添加到项目下的pom.xml文件中:
org.apache.maven.plugins maven-compiler-plugin 1.6 1.6 org.codehaus.mojo findbugs-maven-plugin 2.5.2 true compile check findbugs-test-compile test-compile check
有了这个,如果存在NonNull违规,“mvn clean install”将失败。
报告对我不起作用,因为我正在使用maven 3,报告function在maven 3中已经改变(现在它使用普通的maven插件)
大卫,
您的问题的答案在findbugs maven插件文档中 (参见findbugs:check)