Pmd concurrency issue in gradle 2.4 (with android)

Hi all,

I am switching my android project to gradle 2.4. It’s an android project, but I don’t think this is really related to Android.

Since the migration to 2.4, there is a concurrency issue I can’t work around :
If I build my app with concurrency off (org.gradle.parallel=false in ~/gradle/gradle.properties) then the build goes well and is a success.
If I build my app with concurrency on, then I get PMD failing with this error :

Execution failed for task ‘:common-lib:pmd’. > java.lang.UnsupportedOperationException: The Language for Rule class net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedPrivateFieldRule is immutable and cannot be changed.

I have tried to use pmd.toolVersion = ‘5.0.2’ (and I tried a lot of them) and it doesn’t work. I can see this error message during build :
Build tools null missing. Downloading…
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.

Also, I use a pmd rule set in my project and it looks like it is related to the error I get :
<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=“http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd”>

This ruleset checks my code for bad stuff


Can someone help ?
I think this bug might soon affect the most important apps in Android as they are the ones using quality analysis usually.

I managed to solve the issue. I am not sure to fully understand what’s going on but here the point :

we were using a custom pmd task (extending Pmd to set the ruleset :
task pmd(type: Pmd) {
ruleSets = [] //“java-basic”, “java-braces”, "java-strings"
ruleSetFiles = files("${pmd_rulesetFile}")

source “src”
}

If we do so, the build fails in parallel mode, but works one parallel mode is off. The failure in parallel mode is
Execution failed for task ‘:common-lib:pmd’. > java.lang.UnsupportedOperationException: The Language for Rule class net.sourceforge.pmd.lang.java.rule.unusedcode.UnusedPrivateFieldRule is immutable and cannot be changed.

Now, if use a pmd extension/DSL block, it works in both mode and solves the issue :
pmd {
ruleSetFiles = files("${pmd_rulesetFile}")
}

task pmd(type: Pmd) {
ruleSets = [] //“java-basic”, “java-braces”, "java-strings"
ignoreFailures = false
}

I hope it can help someone to figure out what happens, but this work around works for us.