Maven PMD插件-排除/禁用规则 [英] Maven pmd plugin - Exclude/Disable a rule
问题描述
我正在尝试使用maven-pmd-plugin(在多模块maven项目中)从pmd中排除某些规则.
I'm attempting to exclude a certain rule from pmd using the maven-pmd-plugin (in a multi-module maven project).
方法:
使用excludeFromFailureFile http://maven.apache.org/plugins/maven -pmd-plugin/examples/violation-exclusions.html
Using the excludeFromFailureFile http://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html
理想情况下,我想针对整个产品(基于父包装)排除此规则,但是为了与我一起测试特定的类-即使那是行不通的.
Ideally, I want to exclude this rule for the entire product (based on a parent package), however,to being with I tested for a particular class - even that is not working.
环境
Java 7,Maven 3.0.3
Java 7, Maven 3.0.3
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<configuration>
<excludeFromFailureFile>exclude-pmd.properties</excludeFromFailureFile>
</configuration>
</execution>
<execution>
<goals>
<goal>cpd-check</goal>
</goals>
<!-- Added explicit execution Id to avoid the below problem -->
<!-- 'build.pluginManagement.plugins.plugin[org.apache.maven.plugins:maven-pmd-plugin].executions.execution.id' must be unique but found duplicate execution with id default @ line 1423, column 36 -->
<id>cpd-check</id>
</execution>
</executions>
exclude-pmd.properties的内容
Contents of exclude-pmd.properties
mycompany.project.classA=UselessParentheses
推荐答案
排除规则的最简单方法是提供自己的规则集文件.您可以在此问题的答案中看到在哪里可以找到默认规则集文件.如果使用的是Sonar,则可以使用永久链接检索文件.
将文件复制到父模块,然后可以对其进行自定义,删除要排除的规则,并使用以下配置:
在父母 pom.xml
中:
The simplest way to exclude rules, is providing your own ruleset file. You can see where to find the default ruleset file in the answer to this question. If you are using Sonar, you can retrieve the file using the permalink.
Copy the file to your parent module, and then you can customize it, deleting the rules you want to exclude, and use the following configuration:
in the parent pom.xml
:
...
<properties>
<main.basedir>${project.basedir}</main.basedir>
<!-- Some child module could set this to true to skip PMD check -->
<skip.pmd.check>false</skip.pmd.check>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<!-- This is the version I'm using -->
<version>2.7.1</version>
<configuration>
<rulesets>
<ruleset>${main.basedir}/path/to/pmd-rules.xml</ruleset>
</rulesets>
<skip>${skip.pmd.check}</skip>
</configuration>
<executions>
<execution>
<id>pmd-config</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
在子模块模块中 pom.xml
:
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
您要跳过的某些模块中(即包含生成的代码):
in some module you want to skip (i.e contains generated code):
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
<skip.pmd.check>true</skip.pmd.check>
</properties>
希望获得帮助!
这篇关于Maven PMD插件-排除/禁用规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!