我正在尝试使用maven-pmd-plugin(在多模块maven项目中)从pmd中排除某个规则.
做法:
使用excludeFromFailureFile http://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html
理想情况下,我想要为整个产品(基于父包)排除此规则,但是,我正在测试特定类 - 即使这不起作用.
环境
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>
Run Code Online (Sandbox Code Playgroud)
exclude-pmd.properties的内容
mycompany.project.classA=UselessParentheses
Run Code Online (Sandbox Code Playgroud)
排除规则的最简单方法是提供您自己的规则集文件。您可以在该问题的答案中查看在哪里可以找到默认规则集文件。如果您使用 Sonar,则可以使用永久链接检索文件。
将文件复制到您的父模块,然后您可以对其进行自定义,删除要排除的规则,并使用以下配置:
在父模块 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>
Run Code Online (Sandbox Code Playgroud)
在子模块 pom.xml中:
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
Run Code Online (Sandbox Code Playgroud)
在您想要跳过的 某些模块中(即包含生成的代码):
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
<skip.pmd.check>true</skip.pmd.check>
</properties>
Run Code Online (Sandbox Code Playgroud)
希望这有帮助!
| 归档时间: |
|
| 查看次数: |
6394 次 |
| 最近记录: |