diff options
| author | Joel Klinghed <the_jk@opera.com> | 2017-12-05 11:21:43 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@opera.com> | 2017-12-05 11:21:43 +0100 |
| commit | 6769baf559b6f33ec594843a4c36d5bda5a65db8 (patch) | |
| tree | 6b4c1a38bb56d86a4505eba141cc012c8c9e8060 | |
| parent | b29787d8eeef268c055f7352f0693c7b69351b84 (diff) | |
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
| -rw-r--r-- | src/main/groovy/FlycheckAndroidExperimentalInitPlugin.groovy | 8 | ||||
| -rw-r--r-- | src/main/groovy/FlycheckAndroidJavaTask.groovy | 25 |
2 files changed, 20 insertions, 13 deletions
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<Gradle> { 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 } + } } } |
