Findbugs is an open source project for a static analysis of the Java bytecode to identify potential software bugs.
Step 1: The pom.xml with the findbug & site reporting plugins and properties.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mytutorial</groupId> <artifactId>simpleSpringRestWeb</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>simpleSpringRestWeb</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <slf4j.version>1.7.10</slf4j.version> <commons-logging.version>1.1.1</commons-logging.version> <spring.version>4.0.9.RELEASE</spring.version> <javac.src.version>1.7</javac.src.version> <javac.target.version>1.7</javac.target.version> <test.coverage.rate>100</test.coverage.rate> <cobertura.skip>true</cobertura.skip> <findbugs.skip>false</findbugs.skip> <findbugs.failOnError>false</findbugs.failOnError> </properties> <dependencies> //..... <dependency> <groupId>net.sourceforge.findbugs</groupId> <artifactId>jsr305</artifactId> <version>1.3.7</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <executions> <execution> <goals> <goal>check</goal> </goals> </execution> </executions> <configuration> <effort>Max</effort> <threshold>Low</threshold> <skip>${findbugs.skip}</skip> <failOnError>${findbugs.failOnError}</failOnError> <xmlOutput>true</xmlOutput> <excludeFilterFile>src/main/resources/findbugs/excludeFilter.xml</excludeFilterFile> <outputDirectory>target/site</outputDirectory> <xmlOutput>true</xmlOutput> </configuration> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>2.5.5</version> </plugin> <!-- Normally, we take off the dependency report, saves time. --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.7</version> <configuration> <dependencyLocationsEnabled>false</dependencyLocationsEnabled> </configuration> </plugin> </plugins> </reporting> </project> |
Step 2: Exclude certain classes with an exclude filter
src/main/resources/findbugs/excludeFilter.xml
|
1 2 3 4 5 |
<FindBugsFilter> <Match> <Package name="~.*\.dto.*" /> </Match> </FindBugsFilter> |
Step 3: Running mvn command to spot bugs
|
1 |
mvn clean package |
|
1 2 3 4 5 |
[INFO] Error size is 0 [INFO] Total bugs: 1 [INFO] com.mytutorial.Hello doesn't override org.springframework.hateoas.ResourceSupport.equals(Object) [com.mytutorial.Hello] At Hello.java:[line 1] [INFO] |
Step 4: Running mvn command to report bugs
|
1 |
mvn site |
this creates the file “findbugs.html” under “target/site”, and you can right click on it and open with “web browser”.

