无法在Maven-pmd-plugin 5.0.2中使用自定义规则集 [英] Can't use custom ruleset in maven-pmd-plugin 5.0.2

查看:282
本文介绍了无法在Maven-pmd-plugin 5.0.2中使用自定义规则集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望maven-pmd-plugin包含我指定的规则集,并排除一些规则(特别是UselessParentheses)

I want maven-pmd-plugin to include rulesets that I specify and exclude some rules (specifically, UselessParentheses)

就像文档中所述,我在pmd中放置了以下内容.所有模块的父级xml:

Just like described in documentation, I placed the following in pmd.xml that is parent for all modules:

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

并准备一个自定义规则集,如下所示:

and prepared a custom ruleset like with this:

  <!-- 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运行它显示

Nevertheless, when I run mvn clean jxr:jxr pmd:check I have the "UselessParentheses" in reports. Moreover, running it with -X shows

[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忽略了我的自定义规则集.

So it looks like pmd ignored my custom ruleset.

我希望自定义规则集起作用.我在做什么错了?

I want custom ruleset to work. What am I doing wrong?

推荐答案

您已将 maven-pmd-plugin 配置为

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

Reporting contains the elements that correspond specifically for the site generation phase. Certain Maven plugins can generate reports defined and configured under the reporting element.

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

This means you should execute with the following command:-

mvn clean site

如果您要按照提及的方式执行,请将您的配置复制到内部版本 ,例如

If you would like to execute as you mention, please copy your configure to builds, e.g.

<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的信息.

The result should be as your expected. You can find further about Maven Pom, here.

我希望这会有所帮助.

此致

Charlee Ch.

Charlee Ch.

这篇关于无法在Maven-pmd-plugin 5.0.2中使用自定义规则集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆