Skip to content

Commit

Permalink
Merge pull request #169 from gradle/no/rerun-task
Browse files Browse the repository at this point in the history
Fix bug when calling `--rerun-tasks` with configuration cache enabled.
  • Loading branch information
ghale authored May 7, 2021
2 parents 5e3118d + 74735ab commit c646d96
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ abstract class AbstractCompileLibraryResourcesWorkaround_4_2_orHigher implements
return Class.forName('com.android.build.gradle.tasks.CompileLibraryResourcesTask')
}

protected void setPropertyValue(Task task, ConfigurableFileCollection directoryProperty) {
Field field = task.class.getDeclaredFields().find { it.name == "__${propertyName}__" }
field.setAccessible(true)
field.set(task, directoryProperty)
}

@Override
void apply(WorkaroundContext context) {
Project project = context.project
Expand All @@ -34,17 +28,23 @@ abstract class AbstractCompileLibraryResourcesWorkaround_4_2_orHigher implements
.withPropertyName("${propertyName}.workaround")
.optional()
project.gradle.taskGraph.whenReady {
def propName = propertyName
def setPropertyValue = { ConfigurableFileCollection directoryProperty ->
Field field = task.class.getDeclaredFields().find { it.name == "__${propName}__" }
field.setAccessible(true)
field.set(task, directoryProperty)
}

originalPropertyValue.from(task.getProperty(propertyName))
def dummyProperty = project.objects.fileCollection()
// Non-existent file to give the ConfigurableFileCollection a value.
dummyProperty.setFrom(project.file('/doesnt-exist'))
setPropertyValue(task, dummyProperty)
setPropertyValue(dummyProperty)

// Set the task property back to its original value
task.doFirst {
setPropertyValue(it, originalPropertyValue)
setPropertyValue(originalPropertyValue)
}

}
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/test/groovy/org/gradle/android/RerunTasksTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.gradle.android

import org.gradle.testkit.runner.TaskOutcome
import org.gradle.util.VersionNumber
import org.junit.Assume

@MultiVersionTest
class RerunTasksTest extends AbstractTest {

def "test with configuration cache and --rerun-tasks works"() {
Assume.assumeTrue(TestVersions.latestAndroidVersionForCurrentJDK() >= VersionNumber.parse("4.2.0-alpha01"))

def projectDir = temporaryFolder.newFolder()
SimpleAndroidApp.builder(projectDir, cacheDir)
.withKotlinVersion(VersionNumber.parse("1.5.0"))
.build()
.writeProject()

withGradleVersion("7.0")
.withProjectDir(projectDir)
.withArguments("assembleDebug", "--stacktrace", "--rerun-tasks", "--configuration-cache")
.build()

when:
def result = withGradleVersion("7.0")
.withProjectDir(projectDir)
.withArguments("assembleDebug", "--stacktrace", "--rerun-tasks", "--configuration-cache")
.build()

then:
result.task(":library:assembleDebug").outcome == TaskOutcome.SUCCESS
result.task(":library:compileDebugLibraryResources").outcome == TaskOutcome.SUCCESS
}
}
3 changes: 2 additions & 1 deletion src/test/groovy/org/gradle/android/SimpleAndroidApp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ class SimpleAndroidApp {
boolean kaptWorkersEnabled = true
RoomConfiguration roomConfiguration = RoomConfiguration.ROOM_EXTENSION

VersionNumber androidVersion = Versions.latestAndroidVersion()
VersionNumber androidVersion = TestVersions.latestAndroidVersionForCurrentJDK()
VersionNumber kotlinVersion = TestVersions.latestSupportedKotlinVersion()

File projectDir
File cacheDir

Expand Down

0 comments on commit c646d96

Please sign in to comment.