I'm on creating a maven based java project, which contains the PMD maven plugin. I use my own rule set XML and it works like a charm, except two rule sets: the emptycode and the unnecessary: when I run the build, maven says: "can't find resource". The role definitions look like:
<role ref="rulesets/emptycode" />
and
<role ref="rulesets/unnecessary" />
In every other cases, this kind of definition works. What I found out is that: there is a rule set with the name "unnecessary" under ecmasrcipt category, so maybe this definition needs some suggestion to use java version. I tried multiple thinks, like set language attribute to the ruleset xml node ("JAVA", based on PMD JavaDoc), and some pre-postfix in ref, but it doesn't work and I found no working solution over the web. Does someone has an idea, what I forgot to set, or what I fail? Thanks for any help!
PMD seems to be a fiddly beastie to use from Maven. I've just figured this out with version 3.0 of the plugin - there are two solutions:
The quick-and-dirty solution: put rulesets in your project:
lib/pmd-x.x.x.jar
rulesets/<type>/<ruleset>.xml
files you want to use${basedir}/pmd/...
reference them as follows:
The advantage is this is easy, the disadvantage is if you update the PMD version in future you'll need to remember to update these files.
The nice solution: reference rulesets in
pmd-x.x.x.jar
.${basedir}/pmd/custom.xml
(see http://pmd.sourceforge.net/pmd-5.0.2/howtomakearuleset.html)<rule ref="rulesets/java/imports.xml"/>
pmd-x.x.x.jar
(see quick-and-dirty above) with no leading slashreference your custom ruleset as follows:
The advantage is this will always reference the current PMD rulesets from the PMD jar, the disadvantage is it's a bit fiddly to get right.
To experiment with this until it was working (
maven-pmd-plugin
version 3.0) I kept running mvn pmd:pmd (<linkXref>false</linkXref>
inpom.xml
) and tweaked the paths until I stopped getting errors.