Skip to content

Commit c646d96

Browse files
authored
Merge pull request #169 from gradle/no/rerun-task
Fix bug when calling `--rerun-tasks` with configuration cache enabled.
2 parents 5e3118d + 74735ab commit c646d96

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ abstract class AbstractCompileLibraryResourcesWorkaround_4_2_orHigher implements
1717
return Class.forName('com.android.build.gradle.tasks.CompileLibraryResourcesTask')
1818
}
1919

20-
protected void setPropertyValue(Task task, ConfigurableFileCollection directoryProperty) {
21-
Field field = task.class.getDeclaredFields().find { it.name == "__${propertyName}__" }
22-
field.setAccessible(true)
23-
field.set(task, directoryProperty)
24-
}
25-
2620
@Override
2721
void apply(WorkaroundContext context) {
2822
Project project = context.project
@@ -34,17 +28,23 @@ abstract class AbstractCompileLibraryResourcesWorkaround_4_2_orHigher implements
3428
.withPropertyName("${propertyName}.workaround")
3529
.optional()
3630
project.gradle.taskGraph.whenReady {
31+
def propName = propertyName
32+
def setPropertyValue = { ConfigurableFileCollection directoryProperty ->
33+
Field field = task.class.getDeclaredFields().find { it.name == "__${propName}__" }
34+
field.setAccessible(true)
35+
field.set(task, directoryProperty)
36+
}
37+
3738
originalPropertyValue.from(task.getProperty(propertyName))
3839
def dummyProperty = project.objects.fileCollection()
3940
// Non-existent file to give the ConfigurableFileCollection a value.
4041
dummyProperty.setFrom(project.file('/doesnt-exist'))
41-
setPropertyValue(task, dummyProperty)
42+
setPropertyValue(dummyProperty)
4243

4344
// Set the task property back to its original value
4445
task.doFirst {
45-
setPropertyValue(it, originalPropertyValue)
46+
setPropertyValue(originalPropertyValue)
4647
}
47-
4848
}
4949
}
5050
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.gradle.android
2+
3+
import org.gradle.testkit.runner.TaskOutcome
4+
import org.gradle.util.VersionNumber
5+
import org.junit.Assume
6+
7+
@MultiVersionTest
8+
class RerunTasksTest extends AbstractTest {
9+
10+
def "test with configuration cache and --rerun-tasks works"() {
11+
Assume.assumeTrue(TestVersions.latestAndroidVersionForCurrentJDK() >= VersionNumber.parse("4.2.0-alpha01"))
12+
13+
def projectDir = temporaryFolder.newFolder()
14+
SimpleAndroidApp.builder(projectDir, cacheDir)
15+
.withKotlinVersion(VersionNumber.parse("1.5.0"))
16+
.build()
17+
.writeProject()
18+
19+
withGradleVersion("7.0")
20+
.withProjectDir(projectDir)
21+
.withArguments("assembleDebug", "--stacktrace", "--rerun-tasks", "--configuration-cache")
22+
.build()
23+
24+
when:
25+
def result = withGradleVersion("7.0")
26+
.withProjectDir(projectDir)
27+
.withArguments("assembleDebug", "--stacktrace", "--rerun-tasks", "--configuration-cache")
28+
.build()
29+
30+
then:
31+
result.task(":library:assembleDebug").outcome == TaskOutcome.SUCCESS
32+
result.task(":library:compileDebugLibraryResources").outcome == TaskOutcome.SUCCESS
33+
}
34+
}

src/test/groovy/org/gradle/android/SimpleAndroidApp.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,9 @@ class SimpleAndroidApp {
451451
boolean kaptWorkersEnabled = true
452452
RoomConfiguration roomConfiguration = RoomConfiguration.ROOM_EXTENSION
453453

454-
VersionNumber androidVersion = Versions.latestAndroidVersion()
454+
VersionNumber androidVersion = TestVersions.latestAndroidVersionForCurrentJDK()
455455
VersionNumber kotlinVersion = TestVersions.latestSupportedKotlinVersion()
456+
456457
File projectDir
457458
File cacheDir
458459

0 commit comments

Comments
 (0)