2017-07-27 72 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