From 6769baf559b6f33ec594843a4c36d5bda5a65db8 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Tue, 5 Dec 2017 11:21:43 +0100 Subject: Support gradle-experimental-0.11.0 Problem with the new gradle-experimental is that tasks are only created if needed, so searching for a generateDebugSources or compile*DebugJavaWithJavac is pointless as unless there is a dependency on them the tasks do not exist Only create the FlycheckAndroidJavaTask for projects that implement either an Android App module or Android Library module so that we can assume there will always be a generateDebugSources task. And use buildTypes and flavors to figure out what compile task names there should be and reference them directly --- .../FlycheckAndroidExperimentalInitPlugin.groovy | 8 +++++-- src/main/groovy/FlycheckAndroidJavaTask.groovy | 25 ++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src/main') diff --git a/src/main/groovy/FlycheckAndroidExperimentalInitPlugin.groovy b/src/main/groovy/FlycheckAndroidExperimentalInitPlugin.groovy index ad44335..53cbc7c 100644 --- a/src/main/groovy/FlycheckAndroidExperimentalInitPlugin.groovy +++ b/src/main/groovy/FlycheckAndroidExperimentalInitPlugin.groovy @@ -6,8 +6,12 @@ import org.gradle.api.invocation.Gradle class FlycheckAndroidExperimentalInitPlugin implements Plugin { void apply(Gradle gradle) { gradle.allprojects { project -> - project.task('flycheckAndroidJava', - type: FlycheckAndroidJavaTask) + project.plugins.whenPluginAdded { plugin -> + if (plugin.class.name == 'com.android.build.gradle.model.BaseComponentModelPlugin') { + project.task('flycheckAndroidJava', + type: FlycheckAndroidJavaTask) + } + } } } } diff --git a/src/main/groovy/FlycheckAndroidJavaTask.groovy b/src/main/groovy/FlycheckAndroidJavaTask.groovy index e5fd985..4eadb85 100644 --- a/src/main/groovy/FlycheckAndroidJavaTask.groovy +++ b/src/main/groovy/FlycheckAndroidJavaTask.groovy @@ -6,29 +6,32 @@ import org.gradle.api.tasks.compile.JavaCompile class FlycheckAndroidJavaTask extends DefaultTask { FlycheckAndroidJavaTask() { - def generate = project.tasks.findByName('generateDebugSources') - if (generate) { - dependsOn generate - } + dependsOn 'generateDebugSources' } @TaskAction def action() { - project.tasks.matching({ task -> - if (!(task instanceof JavaCompile)) false - return task.name.startsWith('compile') && - (task.name.endsWith('DebugJavaWithJavac') || - task.name.endsWith('DebugUnitTestJavaWithJavac')) - }).each { compile -> + def buildTypes = project.extensions.buildTypes.names + if (buildTypes.isEmpty()) buildTypes = ['debug', 'release'] + def flavors = project.extensions.flavors.names + def configurations = ['', 'UnitTest'] + configurations.each { configuration -> + def name = 'compile' + if (!flavors.isEmpty()) name += flavors.first().capitalize() + if (!buildTypes.isEmpty()) name += buildTypes.first().capitalize() + name += configuration.capitalize() + 'JavaWithJavac' + def compile = project.tasks.findByName(name) + if (compile) { println '***' println 'args=' + compile.options.compilerArgs println 'encoding=' + compile.options.encoding - println 'bootcp=' + compile.options.bootClasspath + println 'bootcp=' + (compile.options.bootClasspath ?: '') println 'cp=' + compile.classpath.asPath println 'source=' + compile.sourceCompatibility println 'target=' + compile.targetCompatibility println 'files=' + compile.inputs.files.asPath println 'output=' + compile.destinationDir } + } } } -- cgit v1.2.3-70-g09d2