4

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?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • I'm really curious to see how you'll solve this :) – Pascal Thivent Nov 12 '10 at 09:14
  • Me too. I am something of a hacker, but I'm trying to figure out if I'm crazy enough to pull this off: read the config of the Maven PMD plugin, find the referenced ruleset files, collect their rules and create a .rules file using these rules that eclipse can use. Sounds like me, doesn't it ? :-) This is of course in the context of my m2eclipse question: http://stackoverflow.com/questions/4122308/can-i-configure-m2eclipse-through-pom-xml – Sean Patrick Floyd Nov 12 '10 at 09:18
  • Yes, I figured out recent questions were related to this one. And yes, it definitely does sound like you >:) – Pascal Thivent Nov 12 '10 at 14:12

1 Answers1

2

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.

Péter Török
  • 114,404
  • 31
  • 268
  • 329
  • JSP is evil :-) We use wicket, so there's only Java here (and some minimal HTML) – Sean Patrick Floyd Nov 12 '10 at 14:34
  • @seanizer, ours is a legacy project. In theory I tend to agree with you, but as our GUI is dead simple, we hardly ever need to touch the JSP code. Thus replacing it with something more modern/secure/younameit is not our top priority. – Péter Török Nov 13 '10 at 21:52