Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run findbugs automatically in maven on install

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?

like image 372
user82928 Avatar asked Oct 29 '09 01:10

user82928


People also ask

How do you generate FindBugs report?

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.

What is the use of FindBugs?

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.


2 Answers

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.

like image 89
Pascal Thivent Avatar answered Oct 23 '22 06:10

Pascal Thivent


<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

like image 36
jitter Avatar answered Oct 23 '22 06:10

jitter