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
?

- 90,663
- 31
- 146
- 203

- 57,710
- 92
- 283
- 453
-
I was considering triggering an ant task, but may be there is a better way with the maven-findbugs-plugin. – Jérôme Verstrynge Aug 12 '11 at 11:32
2 Answers
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

- 2,637
- 2
- 25
- 13
-
thanks, that works! But is there any way to generate html output in case of `
true ` ? That would be awesome) – Enigo Jul 27 '16 at 07:36 -
@[Enigo](http://stackoverflow.com/users/5151575/enigo) check this answer : http://stackoverflow.com/a/38655823/636849 – Lucas Cimon Jan 18 '17 at 11:20
-
-
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. – Rahul Munjal Mar 08 '17 at 07:21
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!

- 412,405
- 93
- 575
- 722
-
It looks like an interesting tool, but I am currently having a bit of trouble making it work. – Jérôme Verstrynge Aug 12 '11 at 14:54
-
4WHOOOOOOOOOOOOOOOOAAAAAAAAAAAAA (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 !!! – Jérôme Verstrynge Aug 12 '11 at 15:52
-
@JVerstry Glad to help! Actually, it is possible to give me 1k points via a bounty :) – Bohemian May 24 '12 at 05:47
-
1downvoted. The question is about FindBugs. I can't switch to Sonar, so this could be a comment, but not an answer. – Thiago Negri Jan 24 '14 at 09: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 Jan 24 '14 at 10:00