在Maven PMD插件中忽略skipAnnotations

时间:2017-07-27 15:30:40

标签: maven pmd

我为默认的PMD skipAnnotations规则集指定值为true的{​​{1}}:

strings.xml

在像

这样的简单情况下会被忽略
<rule ref="rulesets/java/strings.xml">
    <properties>
        <property name="skipAnnotations" value="true"/>
    </properties>
</rule>

即。由于public class NewMain { @SuppressWarnings("PMD.UnusedFormalParameter") private void method1(Object arg1) { System.out.println("method1"); } @SuppressWarnings("PMD.UnusedFormalParameter") private void method2(Object arg1) { System.out.println("method2"); } @SuppressWarnings("PMD.UnusedFormalParameter") private void method3(Object arg1) { System.out.println("method3"); } @SuppressWarnings("PMD.UnusedFormalParameter") private void method4(Object arg1) { System.out.println("method4"); } } mvn validate失败。

MCVE位于https://github.com/krichter722/pmd-skip-annotations-demo

我正在使用Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:3.8:check (pmd-check) on project pmd-skip-annotations-demo: You have 1 PMD violation. [...] 3.8。

1 个答案:

答案 0 :(得分:2)

属性对应于给定规则,而不是整个规则集。因此,您的配置无效,您应该写:

<rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals">
    <properties>
        <property name="skipAnnotations" value="true"/>
    </properties>
</rule>

要包含整个字符串规则集,但要具有此属性,则应编写

<rule ref="rulesets/java/strings.xml">
    <exclude name="AvoidDuplicateLiterals"/>
</rule>
<rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals">
    <properties>
        <property name="skipAnnotations" value="true"/>
    </properties>
</rule>