我想在POM中排除单个PMD规则,但它不起作用。 我尝试创建一个pmd-exclude.xml(与pom.xml在同一个目录中):
<?xml version="1.0"?>
<ruleset name="remove_rules">
<description>Remove rules</description>
<rule ref="rulesets/unnecessary.xml">
<exclude name="UselessParentheses"/>
</rule>
</ruleset>
来自http://www.ing.iac.es/~docs/external/java/pmd/howtomakearuleset.html并在pom.xml中引用它:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<sourceEncoding>utf-8</sourceEncoding>
<rulesets>
<ruleset>${pom.basedir}/pmd-exclude.xml</ruleset>
</rulesets>
</configuration>
</plugin>
但它一直在报告这些规则。
另外:我不想指定它必须检查哪些规则,因为较新版本可以(并且将)包含新规则,我不想检查每个新版本中将运行哪些新规则。
答案 0 :(得分:6)
我认为您需要添加要检查的规则集,并且只丢弃您不需要的特定规则。
pmd-exclude.xml应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Android Application Rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" >
<description>Remove rules</description>
<rule ref="rulesets/clone.xml" />
<rule ref="rulesets/finalizers.xml" />
<rule ref="rulesets/imports.xml" />
<rule ref="rulesets/logging-java.xml" />
<rule ref="rulesets/unnecessary.xml" >
<exclude name="UselessParentheses" />
</rule>
</ruleset>
答案 1 :(得分:0)
实施例
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.6</version>
<configuration>
<rulesets>
<ruleset>${project.parent.basedir}/pmd-exclude.xml</ruleset>
</rulesets>
</configuration>
</plugin>