| ------ |
| Using Rule Sets |
| ------ |
| Maria Odea Ching |
| ------ |
| 2018-01-10 |
| ------ |
| |
| ~~ 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. |
| |
| ~~ NOTE: For help with the syntax of this file, see: |
| ~~ http://maven.apache.org/doxia/references/apt-format.html |
| |
| 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>. See below for the rules, that are enabled with |
| the default rule set. |
| |
| There are many more rules available and bundled in the PMD code analysis tool: |
| |
| * {{{https://pmd.github.io/pmd-${pmdVersion}/pmd_rules_java.html}Java Rule Index}} |
| |
| * {{{https://pmd.github.io/pmd-${pmdVersion}/pmd_rules_ecmascript.html}JavaScript Rule Index}} |
| |
| * {{{https://pmd.github.io/pmd-${pmdVersion}/pmd_rules_jsp.html}JSP Rule Index}} |
| |
| To use other rule sets, you can configure it in the plugin as shown below. |
| The rule sets may reside in the classpath, filesystem or at a URL. For rule sets that are bundled |
| with the PMD tool, you do not need to specificy the absolute path of the file. It will be resolved by |
| the plugin. But if the rule set is a custom rule set, you need to specify its absolute path. |
| |
| See {{{https://pmd.github.io/pmd-${pmdVersion}/pmd_userdocs_making_rulesets.html}Making Rulesets}} |
| if you want to create your own custom ruleset. |
| |
| <<Note:>> Starting with PMD 5.0 and Maven PMD Plugin 3.0 the paths to the |
| bundled rule sets for the Java language were changed from |
| <<</rulesets/xyz.xml>>> to <<</rulesets/java/xyz.xml>>>. So when upgrading to |
| Maven PMD Plugin 3.0 you may need to alter your plugin configuration. |
| |
| <<Note:>> 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. |
| |
| +-----+ |
| <project> |
| ... |
| <reporting> |
| <plugins> |
| <plugin> |
| <groupId>org.apache.maven.plugins</groupId> |
| <artifactId>maven-pmd-plugin</artifactId> |
| <version>${project.version}</version> |
| <configuration> |
| <rulesets> |
| <!-- A rule set, that comes bundled with PMD --> |
| <ruleset>/category/java/bestpractices.xml</ruleset> |
| <!-- Custom local file system rule set --> |
| <ruleset>d:\rulesets\strings.xml</ruleset> |
| <!-- Custom remote rule set accessed via a URL --> |
| <ruleset>http://localhost/design.xml</ruleset> |
| </rulesets> |
| </configuration> |
| </plugin> |
| </plugins> |
| </reporting> |
| ... |
| </project> |
| +-----+ |
| |
| |
| The default ruleset |
| |
| This is an excerpt of the ruleset <<</rulesets/java/maven-pmd-plugin-default.xml>>>. |
| It contains only rules for Java. |
| If you use a different language, you'll need to specify your own custom ruleset. |
| |
| The current version of the ruleset can be found in version control: |
| {{https://gitbox.apache.org/repos/asf?p=maven-pmd-plugin.git;a=blob_plain;f=src/main/resources/rulesets/java/maven-pmd-plugin-default.xml;hb=HEAD}} |
| |
| +-----+ |
| <rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP" /> |
| <rule ref="category/java/bestpractices.xml/CheckResultSet" /> |
| <rule ref="category/java/bestpractices.xml/UnusedImports" /> |
| <rule ref="category/java/bestpractices.xml/UnusedFormalParameter" /> |
| <rule ref="category/java/bestpractices.xml/UnusedLocalVariable" /> |
| <rule ref="category/java/bestpractices.xml/UnusedPrivateField" /> |
| <rule ref="category/java/bestpractices.xml/UnusedPrivateMethod" /> |
| |
| <rule ref="category/java/codestyle.xml/DontImportJavaLang" /> |
| <rule ref="category/java/codestyle.xml/DuplicateImports" /> |
| <rule ref="category/java/codestyle.xml/ExtendsObject" /> |
| <rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop" /> |
| <rule ref="category/java/codestyle.xml/TooManyStaticImports" /> |
| <rule ref="category/java/codestyle.xml/UnnecessaryFullyQualifiedName" /> |
| <rule ref="category/java/codestyle.xml/UnnecessaryModifier" /> |
| <rule ref="category/java/codestyle.xml/UnnecessaryReturn" /> |
| <rule ref="category/java/codestyle.xml/UselessParentheses" /> |
| <rule ref="category/java/codestyle.xml/UselessQualifiedThis" /> |
| |
| <rule ref="category/java/design.xml/CollapsibleIfStatements" /> |
| <rule ref="category/java/design.xml/SimplifiedTernary" /> |
| <rule ref="category/java/design.xml/UselessOverridingMethod" /> |
| |
| <rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop" /> |
| <rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" /> |
| <rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators" /> |
| <rule ref="category/java/errorprone.xml/AvoidUsingOctalValues" /> |
| <rule ref="category/java/errorprone.xml/BrokenNullCheck" /> |
| <rule ref="category/java/errorprone.xml/CheckSkipResult" /> |
| <rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray" /> |
| <rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices" /> |
| <rule ref="category/java/errorprone.xml/EmptyCatchBlock" /> |
| <rule ref="category/java/errorprone.xml/EmptyFinallyBlock" /> |
| <rule ref="category/java/errorprone.xml/EmptyIfStmt" /> |
| <rule ref="category/java/errorprone.xml/EmptyInitializer" /> |
| <rule ref="category/java/errorprone.xml/EmptyStatementBlock" /> |
| <rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop" /> |
| <rule ref="category/java/errorprone.xml/EmptySwitchStatements" /> |
| <rule ref="category/java/errorprone.xml/EmptySynchronizedBlock" /> |
| <rule ref="category/java/errorprone.xml/EmptyTryBlock" /> |
| <rule ref="category/java/errorprone.xml/EmptyWhileStmt" /> |
| <rule ref="category/java/errorprone.xml/ImportFromSamePackage" /> |
| <rule ref="category/java/errorprone.xml/JumbledIncrementer" /> |
| <rule ref="category/java/errorprone.xml/MisplacedNullCheck" /> |
| <rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode" /> |
| <rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" /> |
| <rule ref="category/java/errorprone.xml/UnconditionalIfStatement" /> |
| <rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" /> |
| <rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals" /> |
| <rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" /> |
| |
| <rule ref="category/java/multithreading.xml/AvoidThreadGroup" /> |
| <rule ref="category/java/multithreading.xml/DontCallThreadRun" /> |
| <rule ref="category/java/multithreading.xml/DoubleCheckedLocking" /> |
| |
| <rule ref="category/java/performance.xml/BigIntegerInstantiation" /> |
| <rule ref="category/java/performance.xml/BooleanInstantiation" /> |
| +-----+ |