According to the official website ( pmd.sourceforge.net ), PMD scans Java source code and looks for potential problems like:
This plugin provides a means to integrate the pmd report into the maven process.
The maven-pmd-plugin is considered an optional maven-plugin, but the default installation of maven comes with it. There is nothing special you need to do, other than use it. see Basic Usage for examples on how to use it.
Starting with the maven-plugin-plugin 1.2 (which first appeared with maven 1.0-rc1), you issue the following command to maven to download the version of your choice.
This command will download the plugin, remove the other versions of the maven-pmd-plugin and make this recently downloaded version immediately available to all projects that depend on maven-pmd-plugin.
The quickest, and easiest way to use the maven-pmd-plugin is to
add the maven-pmd-plugin
entry to your
reports section in your project's project.xml
project descriptor.
The PMD plugin can be started through "maven pmd" or integrated by using the following code snippet in maven.xml:
The generated report has to be added manually to the website which is usually done with navigation.xml.
Assume that you have generated a DB layer having a few
hundreds Java source files. Apart from being curious you
don't want to have a PMD report for generated source files.
Simply put maven.pmd.enable=false
into your
project properties
for that one sub-project.
The maven-pmd-plugin will scan all *.java
files in
your defined <sourceDirectory>
path
specified in your
project descriptor.
Use the maven.pmd.excludes
property to exclude
certain files from being checked by the maven-pmd-plugin.
Lets assume that you have generated a DB layer within your project.
Simply put maven.pmd.excludes=**/database/**
into your
project.properties
file to exclude the files in your
database directory and below.
You could fix the rule violations.
On the other hand, if you want to configure the maven-pmd-plugin to pick and choose the type of tests to perform, then you need to specify your ruleset.
There are two ways to accomplish this.
Define which default pmd rulesets you want to use in the
maven.pmd.rulesetfiles
property.
The default setting for the maven.pmd.rulesetfiles
property is:
The following list of default pmd rulesets was obtained from the official pmd project page.
ruleset/basic.xml
.ruleset/naming.xml
.ruleset/unusedcode.xml
.ruleset/design.xml
.ruleset/imports.xml
.ruleset/junit.xml
.ruleset/strings.xml
.ruleset/braces.xml
.ruleset/codesize.xml
.ruleset/javabeans.xml
.ruleset/coupling.xml
.ruleset/strictexception.xml
.ruleset/controversial.xml
.
Define a custom ruleset.xml and reference it via the
maven.pmd.rulesetfiles
property.
Example of a custom ruleset, saved as file called
favorite-pmd.xml
in your project root.
How it's referenced in your project.properties
file.
The JAR picked up the plugin is defined in $MAVEN_HOME/plugins/pmd/project.xml and can be changed.
Alternatively, you can specify the following in your ~/build.properties file: