Skip to content

Commit 329b209

Browse files
committed
Avoid configuring JavaCompile tasks eagerly.
Fixes #120
1 parent 633c071 commit 329b209

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/main/groovy/org/gradle/android/workarounds/CompilerArgsProcessor.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CompilerArgsProcessor {
4040
}
4141
applied = true
4242

43-
project.tasks.withType(JavaCompile) { JavaCompile task ->
43+
project.tasks.withType(JavaCompile).configureEach { JavaCompile task ->
4444
project.gradle.taskGraph.beforeTask {
4545
if (task == it) {
4646
def processedArgs = processArgs(task.options.compilerArgs, task)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.gradle.android
2+
3+
import org.gradle.util.GradleVersion
4+
import org.gradle.util.VersionNumber
5+
import spock.lang.Unroll
6+
7+
class TaskAvoidanceTest extends AbstractTest {
8+
@Unroll
9+
def "tasks are avoided with #gradleVersion and Android plugin #androidVersion"() {
10+
assert gradleVersion instanceof GradleVersion
11+
assert androidVersion instanceof VersionNumber
12+
13+
println "> Using Android plugin $androidVersion"
14+
println "> Running with $gradleVersion"
15+
16+
SimpleAndroidApp.builder(temporaryFolder.root, cacheDir)
17+
.withAndroidVersion(androidVersion)
18+
.withKotlinDisabled()
19+
.build()
20+
.writeProject()
21+
22+
def originalSettings = file('build.gradle').text
23+
file('build.gradle').text = """
24+
${originalSettings}
25+
26+
allprojects {
27+
tasks.configureEach {
28+
println "configuring \$it"
29+
}
30+
}
31+
"""
32+
33+
when:
34+
def result = withGradleVersion(gradleVersion.version)
35+
.withProjectDir(temporaryFolder.root)
36+
.withArguments("help")
37+
.build()
38+
39+
then:
40+
result.output.contains("configuring task ':help'")
41+
!result.output.contains("configuring task ':app:compileDebugJavaWithJavac'")
42+
!result.output.contains("configuring task ':app:compileDebugAndroidTestJavaWithJavac'")
43+
!result.output.contains("configuring task ':app:compileDebugUnitTestJavaWithJavac'")
44+
!result.output.contains("configuring task ':app:compileReleaseJavaWithJavac'")
45+
!result.output.contains("configuring task ':app:compileReleaseUnitTestJavaWithJavac'")
46+
!result.output.contains("configuring task ':library:compileDebugJavaWithJavac'")
47+
!result.output.contains("configuring task ':library:compileDebugAndroidTestJavaWithJavac'")
48+
!result.output.contains("configuring task ':library:compileDebugUnitTestJavaWithJavac'")
49+
!result.output.contains("configuring task ':library:compileReleaseJavaWithJavac'")
50+
!result.output.contains("configuring task ':library:compileReleaseUnitTestJavaWithJavac'")
51+
52+
where:
53+
[androidVersion, gradleVersion] << Versions.SUPPORTED_VERSIONS_MATRIX.entries().collect { [it.key, it.value] }
54+
}
55+
}

0 commit comments

Comments
 (0)