Issues with M8's PMD plugin


(Jamie Bisotti) #1
  1. I wonder if having ‘ruleSets’ default to ‘basic’ is a good idea. I use a custom ruleset, which I specify with ‘ruleSetFiles’; however, it only includes some of the basic.xml rules. As my code violated some of the basic.xml rules I did not have in my custom ruleset, my build failed until I added “ruleSets = []” too.

  2. Is there a way to exclude some source from being checked? The checkstyle and codenarc plugins seem to have the concept of “exclude”; however, that seems to be missing here. I have one legacy project that has some code I’d like to not check, but some other code I want to check. This was possible with the PMD Ant task I was using previously. Am I missing something? If not, are there plans to expose this in the DSL by/before 1.0?

Thanks,

Jamie


(Peter Niederwieser) #2

ad 1. I think it’s a reasonable default, but I agree that it should not kick in if ‘ruleSetFiles’ is set.

ad 2. Should work like for all other code quality tasks. For example:

tasks.pmd {
  exclude "foo/bar/**"
}

(Jamie Bisotti) #3

I have a multi-project build and the configuration in my root build.gradle looks like this:

...
subprojects() {
    ...
    pmd {
 ruleSetFiles = rootProject.files('config/pmd/rules.xml')
 ruleSets = []
 toolVersion = '4.2.5'
    }
    ...
}
...

As i mentioned, I did not see “exclude” documented anywhere in relation to the PMD plugin. When I change my configuration to add the exclude as you suggest, it looks like this:

pmd {
 ruleSetFiles = rootProject.files('config/pmd/rules.xml')
 ruleSets = []
 toolVersion = '4.2.5'
 exclude '**/npaparser/**/*.java'
        // Line 265
    }

And i get this when I try to execute the build:

FAILURE: Build failed with an exception.
  * Where:
Build file '/home/jbisotti/sandbox/dm-core/build.gradle' line: 265
  * What went wrong:
A problem occurred evaluating root project 'dm-core'.
> Could not find method exclude() for arguments [**/npaparser/**/*.java] on org.gradle.api.plugins.quality.PmdExtension_Decorated@1a15597.

Also, I’m not sure what the difference between “pmd {” and “tasks.pmd {” is, but the latter doesn’t work for me at all – it complains as follows:

FAILURE: Build failed with an exception.
  * Where:
Build file '/home/jbisotti/sandbox/dm-core/build.gradle' line: 261
  * What went wrong:
A problem occurred evaluating root project 'dm-core'.
> Could not find method pmd() for arguments [build_5epactb68o6hnndhnp1kidej0i$_run_closure1_closure16@1571dff] on task set.

On a related note, are these code quality “things” really tasks? I tried to add

onlyIf { !"legacyProjectName".equals(project.name) }

to my PMD “task” configuration; however, it complained that the onlyIf method could not be found on the extension.

Thanks for the help,

Jamie


(Peter Niederwieser) #4

‘pmd {}’ is an extension object brought in by the PMD plugin. It provides a simplified and higher-level way of configuring the PMD tasks. Things like ‘exclude’ and ‘onlyIf’ have to be configured on the tasks themselves. I had though that the task for the main source set is also called ‘pmd’, in which case you would have had to disambiguate with ‘tasks.pmd’. However, I was wrong and the task is called ‘pmdMain’. Hence you can just do:

pmdMain {
    exclude ...
}

Of, if you want to configure all tasks at once:

tasks.withType(Pmd) {
    ...
}

(Jamie Bisotti) #5

I used pmdMain to exclude the pattern in the legacy sub-project’s build.gradle and that seems to have done the trick. However, I’m still not clear if this is a temporary work-around or just “the way” to do this. ???

Thanks for your help.


(Peter Niederwieser) #6

It’s just the way to do this, for all code-quality tasks and all other tasks extending ‘SourceTask’.