Issue
I am trying to add maven pmd plugin in my codebase. added below code in pom file but not sure where to download the pmd_ruleset.xml file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.17.0</version>
<configuration>
<rulesets>
<ruleset>../pmd_ruleset.xml</ruleset>
</rulesets>
<targetJdk>11</targetJdk>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
Actually I tried to download using http://pmd.sourceforge.net/rules/index.html but it is not working. Is there any way to download pmd_ruleset.xml file for maven-pmd-plugin artifact version 3.17.0
Reference - https://maven.apache.org/plugins/maven-pmd-plugin/
Solution
maven-pmd-plugin's latest version is 3.17.0. By default, it will use PMD 6.46.0.
When using maven-pmd-plugin, you don't need to provide your own ruleset. As mentioned in Using Rule Sets:
The PMD plugin ships a default rule set, that has various rules enabled. The ruleset is available as /rulesets/java/maven-pmd-plugin-default.xml.
If you run mvn clean verify
, you can see the ruleset in your maven build directory (for me it's target/pmd/rulesets/maven-pmd-plugin-default.xml
). You can also view it online.
If you'd like to use your own ruleset, you can follow PMD's Making rulesets document and try to make your own ruleset.
It's also possible to download some rulesets online. E.g., you can search PMD rulesets on GitHub.
Answered By - Haoliang
Answer Checked By - Willingham (JavaFixing Volunteer)