Fixed
Status Update
Comments
da...@google.com <da...@google.com> #2
Thanks for the detailed bug report and suggested solution, we'll get it applied soon.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 441e46a0dc02b69de2ea411e913abe4fad328e5a
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Tue Sep 03 10:50:04 2024
Refactor Room Gradle Plugin for lazy configuration
This CL updates the RoomGradlePlugin to adjust for lazy configuration, including schema configurations. There are 3 mayor changes in this CL that all together make the Room Gradle Plugin better work with lazy configurations.
1. The schema configurations are now stored on a DomainObjectSet which enables the plugin to act as schema configuration are added without relying on the timing on how other plugins are configured, i.e. avoid bad patterns like afterEvaluate() or expecting all RoomExtension functions to be called in some withPlugin() lambda. The APIs where also updated to be more Directory centric instead of string based resolving b/279748243 .
2. The plugin was incorrectly using tasks.withType() with a lambda that resolved in eager task configuration. This CL updates the plugin to use configureEach which is lazy. However, due to configuring tasks within a configureEach is not permitted (https://github.com/gradle/gradle/issues/27030 ) the RoomSchemaCopyTask are registered as soon as a user provides a schema configuration and the task itself is then wired when a schema configuration is matched with a variant / target.
3. Updated the schema configuration matching priority to adjust to the laziness of user adding configurations. Specifically the plugin must account that if a user provides a schema configuration that matches all variants and then provides a more specific one (higher priority) the plugin must adjust the registered tasks (see added test testFlavoredProjectPriority() for validation). This is done by storing matches in the CommonIntegration container and later retrieving them when tasks are actually configured.
Bug: 279748243
Bug: 363984118
Test: Existing + manual in sample project
Change-Id: I412d128c70ebab27221d4127294eaa1c4bc4e2e3
M room/integration-tests/kotlintestapp/build.gradle
M room/integration-tests/testapp/build.gradle
M room/room-gradle-plugin/lint-baseline.xml
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomArgumentProvider.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomExtension.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomGradlePlugin.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomSchemaCopyTask.kt
A room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomSimpleCopyTask.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/integration/AndroidPluginIntegration.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/integration/CommonIntegration.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/integration/KotlinMultiplatformPluginIntegration.kt
M room/room-gradle-plugin/src/test/java/androidx/room/gradle/RoomAndroidGradlePluginTest.kt
https://android-review.googlesource.com/3256956
Branch: androidx-main
commit 441e46a0dc02b69de2ea411e913abe4fad328e5a
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Tue Sep 03 10:50:04 2024
Refactor Room Gradle Plugin for lazy configuration
This CL updates the RoomGradlePlugin to adjust for lazy configuration, including schema configurations. There are 3 mayor changes in this CL that all together make the Room Gradle Plugin better work with lazy configurations.
1. The schema configurations are now stored on a DomainObjectSet which enables the plugin to act as schema configuration are added without relying on the timing on how other plugins are configured, i.e. avoid bad patterns like afterEvaluate() or expecting all RoomExtension functions to be called in some withPlugin() lambda. The APIs where also updated to be more Directory centric instead of string based resolving
2. The plugin was incorrectly using tasks.withType() with a lambda that resolved in eager task configuration. This CL updates the plugin to use configureEach which is lazy. However, due to configuring tasks within a configureEach is not permitted (
3. Updated the schema configuration matching priority to adjust to the laziness of user adding configurations. Specifically the plugin must account that if a user provides a schema configuration that matches all variants and then provides a more specific one (higher priority) the plugin must adjust the registered tasks (see added test testFlavoredProjectPriority() for validation). This is done by storing matches in the CommonIntegration container and later retrieving them when tasks are actually configured.
Bug: 279748243
Bug: 363984118
Test: Existing + manual in sample project
Change-Id: I412d128c70ebab27221d4127294eaa1c4bc4e2e3
M room/integration-tests/kotlintestapp/build.gradle
M room/integration-tests/testapp/build.gradle
M room/room-gradle-plugin/lint-baseline.xml
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomArgumentProvider.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomExtension.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomGradlePlugin.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomSchemaCopyTask.kt
A room/room-gradle-plugin/src/main/java/androidx/room/gradle/RoomSimpleCopyTask.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/integration/AndroidPluginIntegration.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/integration/CommonIntegration.kt
M room/room-gradle-plugin/src/main/java/androidx/room/gradle/integration/KotlinMultiplatformPluginIntegration.kt
M room/room-gradle-plugin/src/test/java/androidx/room/gradle/RoomAndroidGradlePluginTest.kt
Description
Component used: KMP + Multiplatform Compose + Android Application Gradle Plugin + Room + KSP Version used: 2.7.0-alpha06
Initially issue was reported to Kotlin Team:https://youtrack.jetbrains.com/issue/KT-70966/Cannot-change-attributes-of-configuration-composeAppdebugFrameworkIosX64-after-it-has-been-locked-for-mutation
Where I've made the investigation and found multiple problems, including room gradle plugin. I found that Room Gradle Plugin has this code :
Calling DomainObjectCollection.html#withType which is equal to
tasks.withType(X::class.java) {}
resolved intotasks.withType(X::class.java).all {}
. It is eager subscription API that will cause all tasks of type X to be resolved as soon as they're registered.The correct API would be:
tasks.withType(X::class.java).configureEach {}
See my report in the comments of KT issue for more details. Reproducer also attached.