Can't use custom ruleset in maven-pmd-plugin 5.0.2

删除回忆录丶 提交于 2019-12-19 07:48:19

问题


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

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>

as a main part.

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.

So it looks like pmd ignored my custom ruleset.

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


回答1:


You've configured the maven-pmd-plugin as a reporting which is

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>

Then when you execute the

mvn clean jxr:jxr pmd:check

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

I hope this may help.

Regards,

Charlee Ch.



来源:https://stackoverflow.com/questions/15133822/cant-use-custom-ruleset-in-maven-pmd-plugin-5-0-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!