Analyzing code with the Maven FindBugs plugin
FindBugs is another tool that uses static analysis to inspect Java bytecode for bugs in a Java code. It is based on the concept of bug patterns. A bug pattern is a code snippet that is often an error.
How to do it...
Let us see how we can use the Maven FindBugs plugin to analyze and identify defects in our code:
Open the Maven project for which you want to do the FindBugs analysis.
Run the following command:
mvn clean compile findbugs:findbugs
Observe the output:
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ project-with-violations --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:\projects\apache-maven cookbook\project-with-violations\target\classes [INFO] [INFO] --- findbugs-maven-plugin:3.0.0:findbugs (default-cli) @ project-with-violations --- [INFO] Fork Value is true [java] Warnings generated: 3 [INFO] Done FindBugs Analysis....
Open the generated XML file
findbugsXml.xml
in thetarget...