views:

288

answers:

2

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?

+1  A: 
<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

jitter
+2  A: 

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.

Pascal Thivent
Thank you for breaking it down for me. This is exactly the kind of solution I was seeking.
You're welcome! Glad you found this helpful.
Pascal Thivent