2017-07-27 332 views
0

我与价值true指定skipAnnotations默认PMD strings.xml规则集:skipAnnotations在Maven的PMD插件忽略

<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由于失败到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. [...]

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

我正在使用maven-pmd-plugin 3.8。

回答

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> 
+0

我明白了,谢谢你。我如何从文档中弄清楚这一点?我似乎没有找到解释或链接使用属性的Maven PMD插件页面。我会很感激的信息,并最终建议改进,以便更容易找到。 –

+1

这根本不是一个真正的Maven问题。 Maven插件只是封装了PMD Ant任务。无论您如何使用它(IDE​​,Gradle,Maven,Ant,CLI ...),PMD的配置都是相同的。请参阅关于如何设置规则集的官方文档:https://pmd.github.io/pmd-5.8.1/customizing/howtomakearuleset.html – Johnco