I’m moving towards centralizing some project configuration, like static code analysis, code coverage and likes. Problem is that the Gradle PMD plugin expects a file as the rule set location thus forcing each project to copy the rule set. I don’t see why it can’t use a URI instead. Currently I’m working around it by doing the following:
afterEvaluate {
def pmdRuleSet = file("${tempDir}/ruleset.xml")
if (!pmdRuleSet.exists()) {
tempDir.mkdirs()
download("${projectURI}/src/main/config/pmd/ruleset.xml", tempDir.absolutePath)
} else {
println "Found PMD ruleset at ${pmdRuleSet}."
}
pmd {
toolVersion = props['pmdVersion']
sourceSets = [sourceSets.main]
ignoreFailures = true
targetJdk = props['projectSourceCompatibility']
ruleSetFiles = files("${tempDir}/ruleset.xml")
}
}
def download(address, downloadLocation = "${tempDir}") {
def f = new File(downloadLocation, address.tokenize("/")[-1])
def fos = new FileOutputStream(f)
def out = new BufferedOutputStream(fos)
out << new URL(address).openStream()
out.close()
println "Downloaded ${address} to ${f.absolutePath}."
f.absolutePath
}
By the way, I wanted to use gradle.projectsLoaded instead of afterEvaluate but the former doesn’t seem to get executed at all.