Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Apache Maven Cookbook

You're reading from  Apache Maven Cookbook

Product type Book
Published in Apr 2015
Publisher Packt
ISBN-13 9781785286124
Pages 272 pages
Edition 1st Edition
Languages

Table of Contents (18) Chapters

Apache Maven Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started 2. IDE Integration with Maven 3. Maven Lifecycle 4. Essential Maven Plugins 5. Dependency Management 6. Code Quality Plugins 7. Reporting and Documentation 8. Handling Typical Build Requirements 9. Multi-module Projects 10. Java Development with Maven 11. Advanced Maven Usage 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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}