Skip to content

Commit 5f7d4ea

Browse files
committed
Replace custom RoomSchemaArgProvider in favor of the new Room Gradle plugin
> Since Room 2.6.0, a Gradle plugin was released to solve various existing issues in Room regarding having inputs and outputs of schemas via Gradle annotation processor options. > Changelog: https://developer.android.com/jetpack/androidx/releases/room#2.6.0-alpha02 See gradle/android-cache-fix-gradle-plugin#544 for reference.
1 parent 5087c86 commit 5f7d4ea

File tree

4 files changed

+8
-20
lines changed

4 files changed

+8
-20
lines changed

build-logic/convention/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies {
4141
compileOnly(libs.firebase.performance.gradlePlugin)
4242
compileOnly(libs.kotlin.gradlePlugin)
4343
compileOnly(libs.ksp.gradlePlugin)
44+
compileOnly(libs.room.gradlePlugin)
4445
}
4546

4647
gradlePlugin {

build-logic/convention/src/main/kotlin/AndroidRoomConventionPlugin.kt

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.google.devtools.ksp.gradle.KspExtension
17+
import androidx.room.gradle.RoomExtension
1818
import com.google.samples.apps.nowinandroid.libs
1919
import org.gradle.api.Plugin
2020
import org.gradle.api.Project
21-
import org.gradle.api.tasks.InputDirectory
22-
import org.gradle.api.tasks.PathSensitive
23-
import org.gradle.api.tasks.PathSensitivity
2421
import org.gradle.kotlin.dsl.configure
2522
import org.gradle.kotlin.dsl.dependencies
26-
import org.gradle.process.CommandLineArgumentProvider
27-
import java.io.File
2823

2924
class AndroidRoomConventionPlugin : Plugin<Project> {
3025

3126
override fun apply(target: Project) {
3227
with(target) {
28+
pluginManager.apply("androidx.room")
3329
pluginManager.apply("com.google.devtools.ksp")
3430

35-
extensions.configure<KspExtension> {
31+
extensions.configure<RoomExtension> {
3632
// The schemas directory contains a schema file for each version of the Room database.
3733
// This is required to enable Room auto migrations.
3834
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration.
39-
arg(RoomSchemaArgProvider(File(projectDir, "schemas")))
35+
schemaDirectory("$projectDir/schemas")
4036
}
4137

4238
dependencies {
@@ -46,16 +42,4 @@ class AndroidRoomConventionPlugin : Plugin<Project> {
4642
}
4743
}
4844
}
49-
50-
/**
51-
* https://issuetracker.google.com/issues/132245929
52-
* [Export schemas](https://developer.android.com/training/data-storage/room/migrating-db-versions#export-schemas)
53-
*/
54-
class RoomSchemaArgProvider(
55-
@get:InputDirectory
56-
@get:PathSensitive(PathSensitivity.RELATIVE)
57-
val schemaDir: File,
58-
) : CommandLineArgumentProvider {
59-
override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}")
60-
}
6145
}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ plugins {
4343
alias(libs.plugins.ksp) apply false
4444
alias(libs.plugins.roborazzi) apply false
4545
alias(libs.plugins.secrets) apply false
46+
alias(libs.plugins.room) apply false
4647
}

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ firebase-crashlytics-gradlePlugin = { group = "com.google.firebase", name = "fir
148148
firebase-performance-gradlePlugin = { group = "com.google.firebase", name = "perf-plugin", version.ref = "firebasePerfPlugin" }
149149
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
150150
ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" }
151+
room-gradlePlugin = { group = "androidx.room", name = "room-gradle-plugin", version.ref = "room" }
151152
work-testing = { group = "androidx.work", name = "work-testing", version = "2.8.1" }
152153

153154
[plugins]
@@ -164,6 +165,7 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi
164165
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
165166
protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }
166167
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
168+
room = { id = "androidx.room", version.ref = "room" }
167169
secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
168170

169171
# Plugins defined by this project

0 commit comments

Comments
 (0)