简体   繁体   中英

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

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?

You can include other rulesets in a PMD ruleset file, eg

<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 . Ie in our case, we had to create separate rulesets for Java and JSP.

I learned the tricks myself from this page .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM