Skip to content

Commit 07447e9

Browse files
committed
Keep TaskProviders out of the unit-test task's onlyIf spec for configuration-cache compatibility
The configuration cache serializes the AGP unit-test task's whole state, including its onlyIf specs. The render wiring's onlyIf captured the Wired records, whose RoboSpec/anchor fields hold TaskProviders — realized DefaultTasks — so storing the entry failed with: Task `:app:testDebugUnitTest` of type `com.android.build.gradle.tasks.factory.AndroidUnitTest`: cannot serialize object of type 'org.gradle.api.DefaultTask', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache. and every generateNavGraph/export run needed --no-configuration-cache. Materialize the render-list Files before configuring the test task and let the spec capture only those — plain Files serialize fine. The sysprops were already eager strings; no behavior change. Fixes #1
1 parent ec2ffd1 commit 07447e9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

compose-nav-graph-gradle/src/main/kotlin/com/github/skydoves/navgraph/gradle/NavGraphGradlePlugin.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ public class NavGraphGradlePlugin : Plugin<Project> {
708708
gradle.taskGraph.whenReady {
709709
val active = wired.filter { hasTask(it.anchor.get()) }
710710
if (active.isEmpty()) return@whenReady
711+
// Materialized OUTSIDE the closures attached to the test task: the configuration cache serializes that
712+
// task's whole state — sysprops AND its onlyIf specs — so a spec capturing `active` would drag each
713+
// Wired's TaskProviders (realized DefaultTasks) into the entry and fail serialization. Plain Files don't.
714+
val renderListFiles = active.map { it.renderListFile.get().asFile }
711715
agpTest.get().apply {
712716
filter {
713717
includeTestsMatching("*NavGraphRobolectricRenderTest")
@@ -723,9 +727,7 @@ public class NavGraphGradlePlugin : Plugin<Project> {
723727
}
724728
// Run iff ANY active pipeline has a non-empty render list (a Layoutlib failure to fill somewhere).
725729
onlyIf {
726-
active.any { w ->
727-
w.renderListFile.get().asFile.let { it.isFile && it.readText().isNotBlank() }
728-
}
730+
renderListFiles.any { it.isFile && it.readText().isNotBlank() }
729731
}
730732
// Force the render to run when requested (the prior thumbnails aren't a tracked output of the test).
731733
outputs.upToDateWhen { false }

0 commit comments

Comments
 (0)