无法在maven-pmd-plugin 5.0.2中使用自定义规则集

And*_*tov 5 customization pmd maven-plugin maven

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

就像在文档中描述的那样,我将以下内容放在pmd.xml中,该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>
Run Code Online (Sandbox Code Playgroud)

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

  <!-- 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>
Run Code Online (Sandbox Code Playgroud)

作为主要部分.

然而,当我跑步时,我mvn clean jxr:jxr pmd:check在报告中有"UselessParentheses".而且,用-Xshow来运行它

[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.
Run Code Online (Sandbox Code Playgroud)

所以看起来pmd忽略了我的自定义规则集.

我想要自定义规则集工作.我究竟做错了什么?

Cha*_*suk 5

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

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

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

mvn clean site
Run Code Online (Sandbox Code Playgroud)

如果您想按照提及执行,请将您的配置复制到构建,例如

<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>
Run Code Online (Sandbox Code Playgroud)

然后当你执行

mvn clean jxr:jxr pmd:check
Run Code Online (Sandbox Code Playgroud)

结果应如您所愿.您可以在这里找到有关Maven Pom的更多信息.

我希望这可能有所帮助.

问候,

Charlee Ch.

  • 谢谢.有用.我刚刚在[docs](http://maven.apache.org/plugins/maven-pmd-plugin/examples/usingRuleSets.html)中做了他们所说的一切,但没有得到结果.在"构建"部分中没有关于放置配置的单词. (2认同)