How can I create one top level PMD task that checks all source in a multi project build?

Hi,

I’m using Gradle 2.1 and I’m trying to create a top level PMD task that checks all code in all of the subprojects in my build and creates a single report.

I’ve attempted this by grabbing all the java source dirs and passing them into a top-level PMD project, which seems like a logical way to go about it.

def allSourceDirs = []
  allprojects {
 apply plugin: 'java'
}
  subprojects {
 allSourceDirs.add project.compileJava.source
}
  apply plugin: 'pmd'
  pmd {
 sourceSets = allSourceDirs
 reportsDir = new File(project.buildDir, "reports/pmd")
}

The result is this error, which is presumably something within the PMD plugin trying to work out which project the sources come from:

Could not determine the dependencies of task ':check'.
> No signature of method: org.gradle.api.internal.file.collections.DefaultConfigurableFileTree.getTaskName() is applicable for argument types: (java.lang.String, null) values: [pmd, null]

I then tried a different approach of just specifying a set of files:

sourceSets = [fileTree(dir: project.projectDir, include: ['components/**/*.java', 'common/**/*.java'])]

And it produces the same error:

No signature of method: org.gradle.api.internal.file.CompositeFileTree$FilteredFileTree.getTaskName() is applicable for argument types: (java.lang.String, null) values: [pmd, null]

I am guessing that the sets of file are transparently wrapped during the normal PMD process, but I am not sure how to proceed as I don’t seem to be able to get anything working at the moment, and working from 14 different PMD reports is not productive for the dev team.

Cheers,

Nick

There is no need to aggregate this functionality into a single task on the root project. You can configure the pmd plugin on the individual subprojects and then simply run ‘gradle check’ at the root which would in turn execute the ‘check’ task on every subproject.