13

Has anybody managed to configure the findbugs Maven 3.x plugin to produce both an xml and html report? (I want the xml one for Jenkins and the html one for checking prior to a commit)

I've seen a lot of documentation on the web on setting this up, but most of it appears to be for Maven 2.x, which I know is configured differently (annoyingly the 2.x configuration is silently ignored by 3.x). I'm new to Maven, so I'm not sure if I'm doing something wrong or I'm following old instructions.

My pom contains the following:

</build>
    </plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>2.3.3</version>
            <configuration>
                <!-- findbugs:help -Ddetail=true  for outputDirectory:
                     Location where generated html will be created. 
                 -->
                <outputDirectory>${project.build.directory}/findbugs</outputDirectory>

                <xmlOutput>true</xmlOutput>
                <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
                <xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
                <failOnError>false</failOnError>
            </configuration>
        </plugin>
    </plugins>
</build>

2 Answers 2

22

The Findbugs-Plugin should be in the reportPlugins-Part of the maven-site-plugin.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-site-plugin</artifactId>
      <configuration>
        <reportPlugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
          </plugin>
        </reportPlugins>
      </configuration>
    </plugin>
  </plugins>
</build>

And additionally, findbugs-report is only generated when the source is compiled before running mvn site. When generate the site, i use mvn test site so findbugs generate the report.

4
  • Perfect. Just one thing: I had to add a <version>2.3.3</version> into the inner plugin to get rid of a maven warning message. Thanks
    – Stormcloud
    Dec 20, 2011 at 11:16
  • 2
    BTW, is it possible to have this rule run as part of the build life cycle? I'd like findbugs to fail builds if it finds something serious (it'll also need to generate the HTML report so I can find out what went wrong)
    – Stormcloud
    Dec 20, 2011 at 12:14
  • According to the plugin-website, there is a findbugs:check goal, that is binded to the verify phase by default and let the build fail by any error. But there will only xml output from this goal.
    – Corubba
    Dec 20, 2011 at 20:24
  • Thanks for the info. It explains why I've had so much trouble trying to get it to work! That's an odd and painful way to work - if findbugs is going to break the build (my requirement) then I'd like a human readable report to tell me why! Oh well...
    – Stormcloud
    Dec 21, 2011 at 8:57
3

Check my answer for similar question where I suggest to use XSLT transformations shipped with Findbugs to generate HTML report during an execution of mvn clean install command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.