blob: 6bcfe52068c864d7f988478c49fc6539ba5f33d8 [file] [log] [blame]
------
Usage
------
Maria Odea Ching
------
2017-11-11
------
~~ Licensed to the Apache Software Foundation (ASF) under one
~~ or more contributor license agreements. See the NOTICE file
~~ distributed with this work for additional information
~~ regarding copyright ownership. The ASF licenses this file
~~ to you under the Apache License, Version 2.0 (the
~~ "License"); you may not use this file except in compliance
~~ with the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing,
~~ software distributed under the License is distributed on an
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~~ KIND, either express or implied. See the License for the
~~ specific language governing permissions and limitations
~~ under the License.
Usage
The PMD plugin generates PMD and CPD reports using the PMD code analysis tool.
To include a report with default rule sets and configuration in your project site, set the following in the
<<<\<reporting\>>>> section of your POM:
+-----+
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${project.version}</version>
</plugin>
</plugins>
</reporting>
...
</project>
+-----+
You can also explicitly execute the PMD plugin and generate the same report by setting the plugin in the
<<<\<build\>>>> section of your POM as shown below:
+-----+
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${project.version}</version>
</plugin>
</plugins>
</build>
...
</project>
+-----+
Configuration
The PMD and CPD reports share the same configuration. For example, the following tells Maven to run the PMD
and CPD report as part of the site report generation.
The reports will link directly to the cross-referenced source if you enable this with the <<<linkXRef>>> parameter.
See the {{{http://maven.apache.org/plugins/maven-jxr-plugin/}JXR plugin}} for more details.
If your source uses a non-default encoding, you can use the <<<sourceEncoding>>> parameter to tell Maven which
encoding to use when reading the java source. Note also the ability to exclude source which you want
to ignore.
You can configure the minimum code size which trips the CPD. The default of <<<100>>> tokens corresponds
to approximately 5-10 lines of code.
Since PMD parses the Java source, it needs to know which Java version to use. CPD's default is <<<1.9>>>.
The following is a possible configuration:
+-----+
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<linkXref>true</linkXref>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.5</targetJdk>
<excludes>
<exclude>**/*Bean.java</exclude>
<exclude>**/generated/*.java</exclude>
</excludes>
<excludeRoots>
<excludeRoot>target/generated-sources/stubs</excludeRoot>
</excludeRoots>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
+-----+