PMD ruleset not available in classpath

Hi,

I have a ruleset file (config/PMD/includeRuleset.xml) for PMD which refers to the ruleset files supplied with PMD (like rulesets/java/basic.xml). I have configured Gradle to use my ruleset file:

pmd {
 ruleSetFiles = files("config/PMD/includeRuleset.xml")
}

When I run the ‘check’ target I get: java.lang.RuntimeException: Couldn’t find that class Can’t find resource rulesets/java/basic.xml. Make sure the resource is a valid file or URL or is on the CLASSPATH

So Gradle cannot find the standard rule sets supplied with PMD when they are referred through my own ruleset file.

I need this to have common PMD configuration used both by Gradle and Eclipse.

How can I solve this problem ?

Shouldn’t it be considered a bug that I can’t fine tune the rules configuration of PMD using a ruleset file ?

I can see from the API documentation that I can set a classpath containing my own PMD libraries which I think must be java classes containing rules but I wouldn’t expect it to be necessary to set the classpath for the libraries and rule set files which come together with the PMD executable.

Regards Esben

I’m not particularly familiar with the PMD plugin, but it’s not too much more than a wrapper around the PMD Ant task. If you’ve got the Ant task working, you might be able to see what’s different in the Gradle plugin here.

If you do sort it out, a patch addressing this issue would be most welcome.

Okay, I’ll take a look at some point. I haven’t used PMD through Ant, so I need to digg into that also.

Did you ever come up with a resolution to this? I’m experiencing a similar issue.

I’m on Gradle 1.6 and with the below simple configuration I’m seeing a similar exception as Esben:

pmd {

toolVersion = ‘5.0.3’

ruleSets = [“basic”, “braces”]

}

The text of the exception I get is:

Can’t find resource null. Make sure the resource is a valid file or URL or is

on the CLASSPATH. Here’s the current classpath: c:\Path\to\wrapper\wrapper.jar

It seems like any specified ruleSets causes the issue (I’ve tried just one entry with basics). I have yet to try a custom ruleSetFiles. Running without ruleSets generates a report appropriately.

Disregard - my issue is that for pmd 5 the rule set names change slightly (basic is now java-basic)

@Esben may have fallen for the same trap.

All the PMD version 5 tasks have to be prefaced by java- or someLang-. Some look really funny because of that like java-javabeans.

Matt Sicker wrote correct solution. It is necessary to add java- prefix to the rule name (in case of Java PMD rule). Tested with Gradle 2.0

pmdMain {
    ruleSets = [ "java-basic", "java-strings", "java-braces" ]
}