Book Image

Apache Maven Cookbook

Book Image

Apache Maven Cookbook

Overview of this book

Table of Contents (18 chapters)
Apache Maven Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Open the Maven project for which you want to do the FindBugs analysis.

  2. Run the following command:

    mvn clean compile findbugs:findbugs
    
  3. 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....
    
  4. Open the generated XML file findbugsXml.xml in the target...