简体   繁体   English

PMD自定义规则集-也许您拼错了规则名称?

[英]PMD custom ruleset - Maybe you mispelled a rule name?

I am trying to integrate pmd into my project. 我正在尝试将pmd集成到我的项目中。 But I am getting following error 但我收到以下错误

java.lang.IllegalArgumentException: No rules found. java.lang.IllegalArgumentException:找不到规则。 Maybe you mispelled a rule name? 也许您拼错了规则名称?

The pom.xml entry is as follows - pom.xml条目如下所示-

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>3.7</version>
            <configuration>
                <linkXRef>false</linkXRef>
                <rulesets>             
                    <ruleset>
                        pmdruleset.xml
                    </ruleset>
                </rulesets>
            </configuration>
        </plugin>
    </plugins>
</reporting>

The custom rule set file contains following - 自定义规则集文件包含以下内容-

<?xml version="1.0"?>
<ruleset name="Controversial"
         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

    <description>
        <rule ref="rulesets/java/errorprone.xml/NullAssignment"/>
    </description>
</ruleset>

I am unable to understand what is wrong. 我不明白哪里出了问题。 Can someone help! 有人可以帮忙!

@eclipse-pmd is right, the rule tag needs to be a child of the ruleset tag. @ eclipse-pmd是正确的,rule标签必须是ruleset标签的子元素。

Additionally, the rule you are trying to use (NullAssignment), is not in the ruleset errorprone, but in controversial. 此外,您尝试使用的规则(NullAssignment)不在易于出错的规则集中,而是有争议的。 With PMD 6, the rules have additionally been organized into categories and is now in category "errorprone". 在PMD 6中,这些规则已另外分类,并且现在属于“容易出错”类别。 More on this will follow. 有关此的更多内容。

maven-pmd-plugin 3.7 / PMD 5.5.1 maven-pmd-plugin 3.7 / PMD 5.5.1

You are using maven-pmd-plugin version 3.7 -> this means, you automatically use an old PMD version (version 5.5.1 to be precise). 您正在使用maven-pmd-plugin版本3.7->这意味着,您将自动使用旧的PMD版本(准确地说是版本5.5.1)。 For this version, your ruleset should look like the following: 对于此版本,您的规则集应如下所示:

<?xml version="1.0"?>
<ruleset name="Custom Ruleset"
     xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

    <description>
        Custom Ruleset
    </description>

    <rule ref="rulesets/java/controversial.xml/NullAssignment"/>
</ruleset>

Documentation for PMD 5.5.1 is available at: https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/controversial.html#NullAssignment 有关PMD 5.5.1的文档,请访问: https//pmd.github.io/pmd-5.5.1/pmd-java/rules/java/controversial.html#NullAssignment

maven-pmd-plugin 3.9.0 / PMD 6.0.1 maven-pmd-plugin 3.9.0 / PMD 6.0.1

If you switch to the latest maven-pmd-plugin version 3.9.0, you'll automatically use PMD 6.0.1 and benefit from the latest bugfixes. 如果您切换到最新的maven-pmd-plugin版本3.9.0,将自动使用PMD 6.0.1,并从最新的错误修复中受益。 You can continue to use the ruleset from above, however you'll see a deprecation notice, since we moved the rule. 您可以继续使用上方的规则集,但是由于我们移动了规则,因此您将看到弃用通知。 To get rid of this warning, use the following rule reference: 要摆脱此警告,请使用以下规则参考:

<rule ref="category/java/errorprone.xml/NullAssignment" />

Documentation for PMD 6.0.1 is available at: https://pmd.github.io/pmd-6.0.1/pmd_rules_java_errorprone.html#nullassignment 有关PMD 6.0.1的文档,请访问: https//pmd.github.io/pmd-6.0.1/pmd_rules_java_errorprone.html#nullassignment

Documentation about rulesets is here: https://pmd.github.io/pmd-6.0.1/pmd_userdocs_understanding_rulesets.html 有关规则集的文档在这里: https : //pmd.github.io/pmd-6.0.1/pmd_userdocs_understanding_rulesets.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM