"pmdTest" fails with "Can't find resource null" when ruleSets include "braces" (Gradle 2.0-rc-1)

$ gradle -v
Gradle 2.0-rc-1
  Build time:
 2014-06-06 07:02:41 UTC
Build number: none
        Apache Ant(TM) version 1.9.3 compiled on December 23 2013
        1.7.0_55 (Oracle Corporation 24.51-b03)
         Linux 3.14.5-1-ARCH amd64
$ find -type f | sort
$ gradle pmdTest
:pmdTest FAILED
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':pmdTest'.
> Can't find resource null.
Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: /home/agt/lib/gradle-2.0-rc-1/lib/gradle-launcher-2.0-rc-1.jar
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  Total time: 3.088 secs

Stack trace: https://gist.github.com/agt-the-walker/46e7d4e567a91dd0c8fa#file-gradle-pmdtest-stacktrace

‘build.gradle’ contains:

apply plugin: 'java'
apply plugin: 'pmd'
  repositories { mavenCentral() }
dependencies { testCompile group: 'junit', name: 'junit', version: '4.+' }
  pmd { ruleSets = ["basic", "braces"] }

‘src/test/java/SimpleTest.java’ contains:

import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
   public class SimpleTest {
  public void testEmptyCollection() {
    Collection collection = new ArrayList();

Note that ‘gradle pmdTest’ succeeds if I remove “braces” from ‘ruleSets’.

More details upon request. Thanks for your time.

I have similar problem with the new pmd, try to write:

pmd {
  toolVersion = '4.3'

This solve my problems. But how to solve it with the new PMD I don’t know. I think that they change the names of the ruleSets or something like this.

Following http://www.gradle.org/docs/release-candidate/release-notes#default-versions-of-code-quality-tools-updated was enough to solve the problem:

pmd { ruleSets = ["java-basic", "java-braces"] }
1 Like

This is the correct solution. If you don’t pin the PMD version to be used, recent Gradle versions will give you 5.x by default, which changed some rule names by prefixing them with ‘java-’.

Nitpick, the link should go to 2.0 release notes: http://www.gradle.org/docs/2.0/release-notes

And BTW, the Gradle example in the docs still shows the old ruleset names in the example: http://www.gradle.org/docs/2.0/dsl/org.gradle.api.plugins.quality.Pmd.html