11

I am trying to integrate FindBugs in a maven project. Does anyone have a sample pom.xml generating a simple findbug HTML report in target? Is it possible to generate this report without having to run site:site?

1
  • I was considering triggering an ant task, but may be there is a better way with the maven-findbugs-plugin. Commented Aug 12, 2011 at 11:32

2 Answers 2

29

Findbugs jar contains 5 XSLT transformations that can be used to convert hard to read XML to easy to read HTML so we can use xml-maven-plugin plugin to execute transformation and here is the configuration:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>2.4.0</version>
        <executions>
            <execution>
                <id>findbug</id>
                <phase>verify</phase>
                <goals>
                    <goal>check</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <findbugsXmlOutputDirectory>
                ${project.build.directory}/findbugs
            </findbugsXmlOutputDirectory>
            <failOnError>false</failOnError>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xml-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <phase>verify</phase>
                <goals>
                    <goal>transform</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <transformationSets>
                <transformationSet>
                    <dir>${project.build.directory}/findbugs</dir>
                    <outputDir>${project.build.directory}/findbugs</outputDir>
                    <stylesheet>fancy-hist.xsl</stylesheet>
                    <!--<stylesheet>default.xsl</stylesheet>-->
                    <!--<stylesheet>plain.xsl</stylesheet>-->
                    <!--<stylesheet>fancy.xsl</stylesheet>-->
                    <!--<stylesheet>summary.xsl</stylesheet>-->
                    <fileMappers>
                        <fileMapper
                                implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                            <targetExtension>.html</targetExtension>
                        </fileMapper>
                    </fileMappers>
                </transformationSet>
            </transformationSets>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>com.google.code.findbugs</groupId>
                <artifactId>findbugs</artifactId>
                <version>2.0.0</version>
            </dependency>
        </dependencies>
    </plugin>
</plugins>

To get the report just execute mvn clean install.

The above code snippet contains all 5 possible transformations so try them all and hopefully you will find one you like.

I tried it with maven 3 and Finbugs 2.0

4
  • thanks, that works! But is there any way to generate html output in case of <failOnError>true</failOnError> ? That would be awesome)
    – Enigo
    Commented Jul 27, 2016 at 7:36
  • @Enigo check this answer : stackoverflow.com/a/38655823/636849 Commented Jan 18, 2017 at 11:20
  • @LucasCimon yep, I've checked it since it is mine answer lol)
    – Enigo
    Commented Feb 19, 2017 at 13:04
  • getting following error while processing : Unable to get XClass for java/lang/StringBuilder However, files got build but i dodnt find any error log in that. Commented Mar 8, 2017 at 7:21
4

Check out Sonar. It's an open-source, stand-alone, web service that you "submit" your code to and it produces beautiful HTML reports on all kinds of code metrics. It also keeps a history of builds. And best of all, you don't have to modify your builds or poms!

There is a maven goal for it too: sonar:sonar. Jenkins (previously Hudson) has a plugin for it, so it's totally painless if you use that for your CI.

Check it out - you won't be sorry!

5
  • It looks like an interesting tool, but I am currently having a bit of trouble making it work. Commented Aug 12, 2011 at 14:54
  • 4
    WHOOOOOOOOOOOOOOOOAAAAAAAAAAAAA (tears in my eyes) !!! This is better than sex... You make my day/week/month/quarter/year !!! This is dream stuff !!! mvn clean install sonar:sonar + running the sonar server and that's it !!! If I could, i'd give you 1k point for that tip !!! Commented Aug 12, 2011 at 15:52
  • @JVerstry Glad to help! Actually, it is possible to give me 1k points via a bounty :)
    – Bohemian
    Commented May 24, 2012 at 5:47
  • 1
    downvoted. The question is about FindBugs. I can't switch to Sonar, so this could be a comment, but not an answer. Commented Jan 24, 2014 at 9:54
  • 1
    @ThiagoNegri Others clearly disagree. If you bothered to check, you'd see that sonar produces a FindBugs report (and does so without site:site), so this does actually answer the question. Further, sonar is far superior to just FindBugs, so it's answering the question by suggesting an alternative solution to the OP's intention. But thank you for at least saying why you downvoted.
    – Bohemian
    Commented Jan 24, 2014 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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