Apache Maven PMD Plugin

The PMD Plugin allows you to automatically run the PMD code analysis tool on your project's source code and generate a site report with its results. It also supports the separate Copy/Paste Detector tool (or CPD) distributed with PMD.

This version of Maven PMD Plugin uses PMD 7.0.0 and requires Java 8. See Upgrading PMD at Runtime for more information.

The plugin accepts configuration parameters that can be used to customize the execution of the PMD tool.

Goals Overview

This plugin has the following goals:

  • pmd:pmd creates a PMD site report based on the rulesets and configuration set in the plugin. It can also generate a pmd output file aside from the site report in any of the following formats: xml, csv or txt.
  • pmd:aggregate-pmd creates a PMD site report in an aggregator project based on the rulesets and configuration set in the plugin. It can also generate a pmd output file aside from the site report in any of the following formats: xml, csv or txt.
  • pmd:aggregate-pmd-no-fork creates a PMD site report in an aggregator project without forking the test-compile phase again.
  • pmd:cpd creates a report for PMD's Copy/Paste Detector (CPD) tool. It can also generate a cpd results file in any of these formats: xml, csv or txt.
  • pmd:aggregate-cpd creates a report for PMD's Copy/Paste Detector (CPD) tool in an aggregator project. It can also generate a cpd results file in any of these formats: xml, csv or txt.
  • pmd:check fails the build if there were any PMD violations in the source code. This goal invokes automatically pmd:pmd prior to executing itself.
  • pmd:aggregate-pmd-check fails the build in an aggregator project if there were any PMD violations in the source code. This goal invokes automatically pmd:aggregate-pmd prior to executing itself.
  • pmd:cpd-check fails the build if there were any CPD violations in the source code. This goal invokes automatically pmd:cpd prior to executing itself.
  • pmd:aggregate-cpd-check fails the build in an aggregator project if there were any CPD violations in the source code. This goal invokes automatically pmd:aggregate-cpd prior to executing itself.

Usage

General instructions on how to use the PMD Plugin can be found on the usage page. Some more specific use cases are described in the examples given below.

In case you still have questions regarding the plugin's usage, please have a look at the FAQ and feel free to contact the user mailing list. The posts to the mailing list are archived and could already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the mail archive.

If you feel like the plugin is missing a feature or has a defect, you can file a feature request or bug report in our issue tracker. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from our source repository and will find supplementary information in the guide to helping with Maven.

Upgrading Notes

3.22.0

  • Starting with Maven PMD Plugin 3.22.0, the plugin requires PMD version 7.0.0 or higher. PMD 7.0.0 switched to SLF4J and since Maven 3.1.0+ SLF4J is the default logging API. Logs from PMD are now always shown and cannot be disabled at runtime after maven has started. The property showPmdLog makes no sense anymore and is deprecated now. See Maven Logging for how to configure logging. For disabling PMD logs, you'd need to start maven with MAVEN_OPTS=-Dorg.slf4j.simpleLogger.log.net.sourceforge.pmd=off mvn <goals> .
  • The upgrade from PMD 6 to PMD 7.0.0 is a major version change. If you use the default ruleset from Maven PMD Plugin, then everything should just work. But if you use a custom ruleset, you most likely need to review your ruleset and migrate it to PMD 7. Rules might have been renamed or replaced. See Detailed Release Notes for PMD 7 and Migration Guide for PMD 7.
  • If you currently override the dependency to PMD (Upgrading PMD at Runtime) make sure to upgrade PMD as well to 7.0.0 or later when upgrading the Maven PMD Plugin.

3.9.0

  • Starting with PMD 6.0.0 and Maven PMD Plugin 3.9.0, the rules have been reorganized into categories, e.g. /category/java/bestpractices.xml. So when upgrading to Maven PMD Plugin 3.9.0 you should review your plugin configuration and/or custom ruleset. See Using Rule Sets for more information.

Examples

To provide you with better understanding of some usages of the Maven PMD Plugin, you can take a look into the following examples: