It's easy to add the findbugs plugin to maven so that it will run if I do
mvn site
However, I would like it to run whenever I do
mvn install
just like unit tests. That is, I don't want the install to succeed if findbugs finds any bugs. Is there are way for me to do this?
To generate the FindBugs report as part of the Project Reports, add the FindBugs plugin in the <reporting> section of your pom. xml. Then, execute the site plugin to generate the report.
FindBugs is an open source tool used to perform static analysis on Java code. In this article, we're going to have a look at setting up FindBugs on a Java project and integrating it into the IDE and the Maven build.
About the findbugs:check goal, the documentation writes:
Fail the build if there were any FindBugs violations in the source code. An XML report is put out by default in the target directory with the errors. To see more documentation about FindBugs' options, please see the FindBugs Manual.
So this is precisely the goal you're looking for. You now just have to bind the check goal to the install verify phase (the verify phase occurs just before install and is actually made to run any checks to verify the package is valid and meets quality criteria so I think it's a better choice):
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.0.1</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
</project>
Of course, adapt the configuration to suit your needs.
<build>
<plugins>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
...
</configuration>
</plugins>
</build>
findbugs:check goal
findbugs: Violation Checking
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With