代码之家  ›  专栏  ›  技术社区  ›  Kalle Richter

在Maven PMD插件中忽略SkipanNotation

  •  0
  • Kalle Richter  · 技术社区  · 7 年前

    我正在指定 skipAnnotations 有价值的 true 对于默认PMD 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 由于以下原因而失败 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.

    1 回复  |  直到 7 年前
        1
  •  2
  •   Johnco    7 年前

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

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