From 3af80f43b8c7d4dd36ad149f7a5dc647b258330a Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Sun, 31 Dec 2017 16:04:24 -0800 Subject: [PATCH] Pull PMD and FindBugs out into separate projects. This saves ~10-20s so down to around ~2min build. --- build.gradle | 4 +- library/build.gradle | 78 ++--------------------------------- library/findbugs/build.gradle | 31 ++++++++++++++ library/pmd/build.gradle | 39 ++++++++++++++++++ settings.gradle | 2 + 5 files changed, 79 insertions(+), 75 deletions(-) create mode 100644 library/findbugs/build.gradle create mode 100644 library/pmd/build.gradle diff --git a/build.gradle b/build.gradle index 5b33833fdf..28fb6101f6 100644 --- a/build.gradle +++ b/build.gradle @@ -61,7 +61,9 @@ subprojects { project -> } project.afterEvaluate { - if (project.hasProperty("android")) { + if (project.hasProperty("android") + && project.name != 'pmd' + && project.name != 'findbugs') { android { lintOptions { warningsAsErrors true diff --git a/library/build.gradle b/library/build.gradle index ddd3a7b208..fdcc3720d3 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,6 +1,4 @@ apply plugin: 'com.android.library' -apply plugin: 'findbugs' -apply plugin: 'pmd' if (!hasProperty('DISABLE_ERROR_PRONE')) { apply plugin: "net.ltgt.errorprone" @@ -61,79 +59,11 @@ android { } } -afterEvaluate { - if (tasks.findByName("assembleDebug") == null) { - return - } - - findbugs { - toolVersion FINDBUGS_VERSION - } - - tasks.create('findbugs', FindBugs) { - dependsOn tasks.compileDebugJavaWithJavac - - description 'Run findbugs' - group 'verification' - - classes = fileTree(tasks.compileDebugJavaWithJavac.destinationDir) - source android.sourceSets.main.java.srcDirs - classpath = files() - doFirst { - classpath += classPathForQuality() - } - effort = 'max' - excludeFilter = file("findbugs-exclude.xml") - - // Failures are caught and printed by the violations plugin. - ignoreFailures = true - - reports { - xml.enabled = true - html.enabled = false - } - } - - check.dependsOn('findbugs') - - pmd { - toolVersion PMD_VERSION - } - - tasks.create('pmd', Pmd) { - dependsOn tasks.compileDebugJavaWithJavac - targetJdk = TargetJdk.VERSION_1_7 - - description 'Run pmd' - group 'verification' - - // If ruleSets is not empty, it seems to contain some - // defaults which override rules in the ruleset file... - ruleSets = [] - ruleSetFiles = files('pmd-ruleset.xml') - source android.sourceSets.main.java.srcDirs - classpath = files() - classpath += files(tasks.compileDebugJavaWithJavac.destinationDir) - doFirst { - classpath += classPathForQuality() - } - - //TODO enable this once new Gradle containing this flag is out - //see https://github.com/gradle/gradle/pull/3125#issuecomment-352442432 - //incrementalAnalysis = true - - // Failures are caught and printed by the violations plugin. - ignoreFailures = true - - reports { - xml.enabled = true - html.enabled = false - } - } - - check.dependsOn('pmd') -} +check.dependsOn(':library:findbugs:findbugs') +check.dependsOn(':library:pmd:pmd') +// Used in pmd and findbugs subprojects. +@SuppressWarnings("GroovyUnusedDeclaration") def classPathForQuality() { return files( android.bootClasspath, diff --git a/library/findbugs/build.gradle b/library/findbugs/build.gradle new file mode 100644 index 0000000000..a2e5b3f2a2 --- /dev/null +++ b/library/findbugs/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'findbugs' + +findbugs { + toolVersion FINDBUGS_VERSION +} + +def library = project(':library') + +tasks.create('findbugs', FindBugs) { + dependsOn library.tasks.compileDebugJavaWithJavac + + description 'Run findbugs' + group 'verification' + + classes = fileTree(library.tasks.compileDebugJavaWithJavac.destinationDir) + source library.android.sourceSets.main.java.srcDirs + classpath = files() + doFirst { + classpath += library.classPathForQuality() + } + effort = 'max' + excludeFilter = file("${library.projectDir}/findbugs-exclude.xml") + + // Failures are caught and printed by the violations plugin. + ignoreFailures = true + + reports { + xml.enabled = true + html.enabled = false + } +} diff --git a/library/pmd/build.gradle b/library/pmd/build.gradle new file mode 100644 index 0000000000..d02349082c --- /dev/null +++ b/library/pmd/build.gradle @@ -0,0 +1,39 @@ +apply plugin: 'pmd' + +def library = project(':library') + +pmd { + toolVersion PMD_VERSION +} + +tasks.create('pmd', Pmd) { + dependsOn library.tasks.compileDebugJavaWithJavac + targetJdk = TargetJdk.VERSION_1_7 + + description 'Run pmd' + group 'verification' + + // If ruleSets is not empty, it seems to contain some + // defaults which override rules in the ruleset file... + ruleSets = [] + ruleSetFiles = files("${library.projectDir}/pmd-ruleset.xml") + source library.android.sourceSets.main.java.srcDirs + classpath = files() + classpath += files(library.tasks.compileDebugJavaWithJavac.destinationDir) + doFirst { + classpath += library.classPathForQuality() + } + + //TODO enable this once new Gradle containing this flag is out + //see https://github.com/gradle/gradle/pull/3125#issuecomment-352442432 + //incrementalAnalysis = true + + // Failures are caught and printed by the violations plugin. + ignoreFailures = true + + reports { + xml.enabled = true + html.enabled = false + } +} + diff --git a/settings.gradle b/settings.gradle index b6e39d145d..e9e2cce104 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,8 @@ exec { commandLine "git", "submodule", "update", "--init", "--recursive" } include ':library' +include ':library:pmd' +include ':library:findbugs' include ':instrumentation' include ':annotation' include ':annotation:compiler'