In the Eclipe PMD plugin, can I reference the standard ruleset files?

雨燕双飞 提交于 2019-12-10 08:19:40

问题


I would like my eclipse PMD plugin configuration to access the same standard ruleset files as the maven-pmd-plugin.

You can configure the maven pmd plugin to use a custom set of rule sets like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <version>2.5</version>
    <configuration>
      <rulesets>
        <!-- Two rule sets that come bundled with PMD -->
        <ruleset>/rulesets/braces.xml</ruleset>
        <ruleset>/rulesets/naming.xml</ruleset>
        <!-- Custom local file system rule set -->
        <ruleset>d:\rulesets\strings.xml</ruleset>
        <!-- Custom remote rule set accessed via a URL -->
        <ruleset>http://localhost/design.xml</ruleset>
      </rulesets>
    </configuration>
</plugin>

but in the eclipse plugin you can only switch on / turn off individual rules or specify a single ruleset file. Is there perhaps a way that ruleset file can include several others? Or do I have to aggregate that file automatically from the rulesets I want to use?


回答1:


You can include other rulesets in a PMD ruleset file, e.g.

<ruleset ...>
    ...
    <rule ref="rulesets/basic.xml"/>
    ...
    <rule ref="rulesets/strings.xml">
        <exclude name="AvoidDuplicateLiterals"/>
    </rule>
    ...
</ruleset>

This is actually an excerpt from our own ruleset file, so it is proven to work :-)

As you can see, you can exclude/include individual rules from your ruleset, or even reconfigure them. One caveat: you must not mix rules for different languages in a single ruleset. I.e. in our case, we had to create separate rulesets for Java and JSP.

I learned the tricks myself from this page.



来源:https://stackoverflow.com/questions/4155094/in-the-eclipe-pmd-plugin-can-i-reference-the-standard-ruleset-files

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