Book Image

Apache Maven Cookbook

Book Image

Apache Maven Cookbook

Overview of this book

If you are a Java developer or a manager who has experience with Apache Maven and want to extend your knowledge, then this is the ideal book for you. Apache Maven Cookbook is for those who want to learn how Apache Maven can be used for build automation. It is also meant for those familiar with Apache Maven, but want to understand the finer nuances of Maven and solve specific problems.
Table of Contents (13 chapters)
12
Index

Analyzing code with the Maven PMD plugin


PMD is a source code analyzer. It finds common programming flaws such as unused variables, empty catch blocks, and unnecessary object creation. It also includes the Copy/Paste Detector (CPD) that finds duplicated code.

How to do it...

Use the following steps to run PMD on a Maven project:

  1. Open the Maven project for which you want to do a PMD analysis (for instance, project-with-violations).

  2. Run the following command:

    mvn pmd:pmd pmd:cpd
    
  3. Observe the output:

    [INFO] --- maven-pmd-plugin:3.2:pmd (default-cli) @ project-with-violations ---
    [WARNING] Unable to locate Source XRef to link to – DISABLED
    [INFO] --- maven-pmd-plugin:3.2:cpd (default-cli) @ project-with-violations ---
    [WARNING] Unable to locate Source XRef to link to - DISABLED
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    
  4. Check the contents of the target folder:

  5. Open the pmd.xml report:

  6. Open the cpd.html file in the site folder:

How it works...

The...