在Maven的PMD-插件5.0.2不能使用自定义的规则集(Can't use custom

2019-07-20 17:42发布

我想行家-PMD-插件包括我指定并排除一些规则的规则集(具体而言,UselessParentheses)

就像在描述文档 ,我置于pmd.xml即所有模块父以下内容:

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <rulesets>
            <ruleset>/home/ubuntu/ruleset.xml</ruleset>
          </rulesets>
        </configuration>
      </plugin>
    </plugins>
  </reporting>

并准备像这样一个自定义的规则集:

  <!-- We'll use the entire rulesets -->
  <rule ref="rulesets/java/basic.xml"/>
  <rule ref="rulesets/java/imports.xml"/>
  <rule ref="rulesets/java/codesize.xml"/>
  <rule ref="rulesets/java/design.xml"/>
  <rule ref="rulesets/java/strings.xml"/>
  <rule ref="rulesets/java/unusedcode.xml"/>

  <!-- We want everything from this except some -->
  <rule ref="rulesets/java/unnecessary.xml">
    <exclude name="UselessParentheses"/>
  </rule>

作为主要组成部分。

然而,当我运行mvn clean jxr:jxr pmd:check我在报告中的“UselessParentheses”。 此外,与运行它-X节目

[DEBUG] Preparing ruleset: java-basic
[DEBUG] Before: java-basic After: java-basic.xml
[DEBUG] The resource 'rulesets/java/basic.xml' was found as jar:file:/home/ubuntu/.m2/repository/net/sourceforge/pmd/pmd/5.0.2/pmd-5.0.2.jar!/rulesets/java/basic.xml.
[DEBUG] Preparing ruleset: java-unusedcode
[DEBUG] Before: java-unusedcode After: java-unusedcode.xml
[DEBUG] The resource 'rulesets/java/unusedcode.xml' was found as jar:file:/home/ubuntu/.m2/repository/net/sourceforge/pmd/pmd/5.0.2/pmd-5.0.2.jar!/rulesets/java/unusedcode.xml.
[DEBUG] Preparing ruleset: java-imports
[DEBUG] Before: java-imports After: java-imports.xml
[DEBUG] The resource 'rulesets/java/imports.xml' was found as jar:file:/home/ubuntu/.m2/repository/net/sourceforge/pmd/pmd/5.0.2/pmd-5.0.2.jar!/rulesets/java/imports.xml.

因此,它看起来像PMD忽略我的自定义规则集。

我想自定义的规则集来工作。 我究竟做错了什么?

Answer 1:

你已经配置了Maven的PMD-插件的报告是

报告包含专门为网站生成阶段对应的元素。 某些Maven插件可以生成报告要素下定义和配置报告。

这意味着你应该使用以下命令来执行: -

mvn clean site

如果你想执行你提到,请复制你的配置来构建 ,如

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <rulesets>
                    <ruleset>/home/ubuntu/ruleset.xml</ruleset>
                </rulesets>
            </configuration>
        </plugin>
    </plugins>
</build>

然后,当你执行

mvn clean jxr:jxr pmd:check

结果应该是作为你的预期。 您可以进一步找到有关Maven的POM, 在这里 。

我希望这可以帮助。

问候,

Charlee酒店章。



文章来源: Can't use custom ruleset in maven-pmd-plugin 5.0.2