Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Yigit Boyar | 1f8acf7 | 2018-02-08 13:05:00 -0800 | [diff] [blame] | 16 | // TO debug processor, run: |
| 17 | //./gradlew :r:in:k:clean :r:in:k:cC --no-daemon |
| 18 | // -Dorg.gradle.debug=true |
| 19 | // -Dkotlin.compiler.execution.strategy="in-process" |
Dustin Lam | c351bfc | 2020-03-11 20:32:42 -0700 | [diff] [blame] | 20 | |
Daniel Santiago Rivera | 766b4e3 | 2022-08-10 17:50:44 -0700 | [diff] [blame] | 21 | import com.google.devtools.ksp.gradle.KspTask |
Dustin Lam | c351bfc | 2020-03-11 20:32:42 -0700 | [diff] [blame] | 22 | |
Aurimas Liutikas | 238e480 | 2017-12-14 10:52:11 -0800 | [diff] [blame] | 23 | plugins { |
Aurimas Liutikas | 21ff5d1 | 2018-08-15 15:33:13 -0700 | [diff] [blame] | 24 | id("AndroidXPlugin") |
| 25 | id("com.android.application") |
Aurimas Liutikas | 238e480 | 2017-12-14 10:52:11 -0800 | [diff] [blame] | 26 | id("kotlin-android") |
Yigit Boyar | 315ae40 | 2021-07-14 22:07:56 -0700 | [diff] [blame] | 27 | // both ksp and kapt are applied. each run in their own variant. |
| 28 | id("com.google.devtools.ksp") |
| 29 | id("kotlin-kapt") |
Yigit Boyar | 23758df | 2020-12-16 18:47:29 -0800 | [diff] [blame] | 30 | } |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 31 | android { |
Yigit Boyar | af110fe | 2021-01-14 22:53:42 -0800 | [diff] [blame] | 32 | buildFeatures { |
| 33 | buildConfig = true |
| 34 | } |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 35 | defaultConfig { |
Yigit Boyar | 04b0474 | 2021-02-26 12:04:07 -0800 | [diff] [blame] | 36 | multiDexEnabled true |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 37 | javaCompileOptions { |
| 38 | annotationProcessorOptions { |
Yigit Boyar | 60b74ae | 2020-03-10 17:02:50 -0700 | [diff] [blame] | 39 | arguments = [ |
Yigit Boyar | 315ae40 | 2021-07-14 22:07:56 -0700 | [diff] [blame] | 40 | "room.schemaLocation" : "$projectDir/schemas".toString() |
Yigit Boyar | 60b74ae | 2020-03-10 17:02:50 -0700 | [diff] [blame] | 41 | ] |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | } |
Dustin Lam | c351bfc | 2020-03-11 20:32:42 -0700 | [diff] [blame] | 45 | |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 46 | sourceSets { |
Yigit Boyar | 315ae40 | 2021-07-14 22:07:56 -0700 | [diff] [blame] | 47 | androidTestWithKapt.assets.srcDirs += files("$projectDir/schemas".toString()) |
Daniel Santiago Rivera | 766b4e3 | 2022-08-10 17:50:44 -0700 | [diff] [blame] | 48 | androidTestWithKspGenJava.assets.srcDirs += files("$projectDir/schemas-ksp".toString()) |
| 49 | androidTestWithKspGenKotlin.assets.srcDirs += files("$projectDir/schemas-ksp".toString()) |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 50 | } |
Yigit Boyar | 7110304 | 2020-04-06 17:28:21 -0700 | [diff] [blame] | 51 | |
Jeff Gaston | ff3f1b2 | 2020-08-04 11:24:37 -0400 | [diff] [blame] | 52 | flavorDimensions "processorConfiguration" |
| 53 | productFlavors { |
Yigit Boyar | 315ae40 | 2021-07-14 22:07:56 -0700 | [diff] [blame] | 54 | withKapt { |
Jeff Gaston | ff3f1b2 | 2020-08-04 11:24:37 -0400 | [diff] [blame] | 55 | dimension "processorConfiguration" |
| 56 | javaCompileOptions { |
| 57 | annotationProcessorOptions { |
| 58 | arguments = [ |
| 59 | "room.schemaLocation" : "$projectDir/schemas".toString(), |
Jeff Gaston | ff3f1b2 | 2020-08-04 11:24:37 -0400 | [diff] [blame] | 60 | ] |
| 61 | } |
| 62 | } |
| 63 | } |
Daniel Santiago Rivera | 766b4e3 | 2022-08-10 17:50:44 -0700 | [diff] [blame] | 64 | withKspGenJava { |
| 65 | dimension "processorConfiguration" |
| 66 | } |
| 67 | withKspGenKotlin { |
Jeff Gaston | ff3f1b2 | 2020-08-04 11:24:37 -0400 | [diff] [blame] | 68 | dimension "processorConfiguration" |
Jeff Gaston | ff3f1b2 | 2020-08-04 11:24:37 -0400 | [diff] [blame] | 69 | } |
| 70 | } |
Aurimas Liutikas | dcfa035 | 2022-03-14 16:05:33 -0700 | [diff] [blame] | 71 | namespace "androidx.room.integration.kotlintestapp" |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | dependencies { |
Alan Viverette | 6c56334 | 2018-03-08 18:02:39 -0500 | [diff] [blame] | 75 | implementation(project(":room:room-common")) |
Alan Viverette | 6c56334 | 2018-03-08 18:02:39 -0500 | [diff] [blame] | 76 | implementation(project(":room:room-runtime")) |
Clara Fok | 22eccb9 | 2021-06-15 16:32:01 -0700 | [diff] [blame] | 77 | implementation(project(":room:room-paging")) |
Dustin Lam | 1b2b8e2 | 2020-11-19 00:39:04 +0000 | [diff] [blame] | 78 | implementation(projectOrArtifact(":arch:core:core-runtime")) |
Yigit Boyar | a755f33 | 2020-05-30 19:14:46 -0700 | [diff] [blame] | 79 | implementation(projectOrArtifact(":lifecycle:lifecycle-livedata")) |
Yigit Boyar | af110fe | 2021-01-14 22:53:42 -0800 | [diff] [blame] | 80 | implementation(projectOrArtifact(":lifecycle:lifecycle-livedata-ktx")) |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 81 | implementation(libs.kotlinStdlib) |
| 82 | implementation(libs.kotlinCoroutinesAndroid) |
| 83 | implementation(libs.multidex) |
Yigit Boyar | 562a37d | 2020-03-16 13:00:36 -0700 | [diff] [blame] | 84 | // depend on the shadowed version so that it tests with the shipped artifact |
Yigit Boyar | 23758df | 2020-12-16 18:47:29 -0800 | [diff] [blame] | 85 | // this is a temporary attribute until KSP and AndroidX plugin supports variants. |
Daniel Santiago Rivera | 766b4e3 | 2022-08-10 17:50:44 -0700 | [diff] [blame] | 86 | kspAndroidTestWithKspGenJava( |
| 87 | project(path: ":room:room-compiler", configuration: "shadowAndImplementation") |
| 88 | ) |
| 89 | kspAndroidTestWithKspGenKotlin( |
Yigit Boyar | 315ae40 | 2021-07-14 22:07:56 -0700 | [diff] [blame] | 90 | project(path: ":room:room-compiler", configuration: "shadowAndImplementation") |
| 91 | ) |
| 92 | kaptAndroidTestWithKapt( |
| 93 | project(path: ":room:room-compiler", configuration: "shadowAndImplementation") |
| 94 | ) |
Aurimas Liutikas | cb841c5 | 2021-04-01 14:14:10 -0700 | [diff] [blame] | 95 | androidTestImplementation(projectOrArtifact(":lifecycle:lifecycle-livedata-ktx")) |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 96 | androidTestImplementation(libs.testExtJunit) |
| 97 | androidTestImplementation(libs.testCore) |
| 98 | androidTestImplementation(libs.testRunner) { |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 99 | exclude module: "support-annotations" |
| 100 | exclude module: "hamcrest-core" |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 101 | } |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 102 | androidTestImplementation(libs.espressoCore, { |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 103 | exclude group: "com.android.support", module: "support-annotations" |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 104 | exclude module: "hamcrest-core" |
| 105 | }) |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 106 | androidTestImplementation(libs.truth) |
Clara Fok | 22eccb9 | 2021-06-15 16:32:01 -0700 | [diff] [blame] | 107 | androidTestImplementation(libs.kotlinTest) |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 108 | androidTestImplementation(project(":room:room-guava")) |
| 109 | androidTestImplementation(project(":room:room-testing")) |
Clara Fok | 76e8c1e | 2022-04-28 17:05:24 -0700 | [diff] [blame] | 110 | androidTestImplementation(project(":room:room-paging-guava")) |
clarafok | d1ba579 | 2022-05-13 16:09:09 -0700 | [diff] [blame] | 111 | androidTestImplementation(project(":room:room-paging-rxjava2")) |
clarafok | c7b01e9 | 2022-05-12 15:28:45 -0700 | [diff] [blame] | 112 | androidTestImplementation(project(":room:room-paging-rxjava3")) |
Clara Fok | 76e8c1e | 2022-04-28 17:05:24 -0700 | [diff] [blame] | 113 | // we need latest guava android because room-paging-guava's guava-android gets override by |
| 114 | // its kotlinx-coroutines-guava dependency's guava-jre version |
| 115 | androidTestImplementation(libs.guavaAndroid) |
Jim Sproch | 9e38b4f | 2021-01-06 14:21:06 -0800 | [diff] [blame] | 116 | androidTestImplementation(project(":room:room-rxjava2")) |
Yigit Boyar | af110fe | 2021-01-14 22:53:42 -0800 | [diff] [blame] | 117 | androidTestImplementation(project(":room:room-rxjava3")) |
Daniel Santiago Rivera | 1fc1960 | 2019-02-27 15:48:32 -0800 | [diff] [blame] | 118 | androidTestImplementation(project(":room:room-ktx")) |
Clara Fok | 583863d | 2021-08-18 18:28:43 -0700 | [diff] [blame] | 119 | androidTestImplementation(project(":internal-testutils-common")) |
Ian Lake | 005a920 | 2019-09-26 16:17:25 -0700 | [diff] [blame] | 120 | androidTestImplementation("androidx.arch.core:core-testing:2.0.1") |
Dustin Lam | cd9288e | 2022-04-21 15:33:51 -0700 | [diff] [blame] | 121 | androidTestImplementation("androidx.paging:paging-runtime:3.1.1") |
Dustin Lam | 45c4978 | 2022-08-22 19:11:59 +0000 | [diff] [blame] | 122 | androidTestImplementation(projectOrArtifact(":lifecycle:lifecycle-runtime-testing")) |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 123 | androidTestImplementation(libs.rxjava2) |
David Saff | 3382362 | 2022-09-08 09:45:19 -0400 | [diff] [blame] | 124 | androidTestImplementation(libs.kotlinCoroutinesTest) |
Aurimas Liutikas | 759f968 | 2022-10-05 07:01:37 -0700 | [diff] [blame] | 125 | testImplementation(libs.mockitoCore4) |
Florina Muntenescu | 34f575b | 2017-07-17 10:38:50 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Daniel Santiago Rivera | 4297ec0 | 2023-02-06 16:26:18 -0500 | [diff] [blame^] | 128 | class RoomSchemaArgProvider implements CommandLineArgumentProvider { |
Jim Sproch | 3f742d5 | 2023-02-02 13:41:33 -0800 | [diff] [blame] | 129 | |
Daniel Santiago Rivera | 4297ec0 | 2023-02-06 16:26:18 -0500 | [diff] [blame^] | 130 | @InputDirectory |
| 131 | @PathSensitive(PathSensitivity.RELATIVE) |
| 132 | File schemaDir |
| 133 | |
| 134 | @Input |
| 135 | Provider<Boolean> generateKotlin; |
| 136 | |
| 137 | RoomSchemaArgProvider(File schemaDir, Provider<Boolean> generateKotlin) { |
| 138 | this.schemaDir = schemaDir |
| 139 | this.generateKotlin = generateKotlin |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | Iterable<String> asArguments() { |
| 144 | // Note: If you're using KSP, you should change the line below to return |
| 145 | // ["room.schemaLocation=${schemaDir.path}"] |
| 146 | return [ |
| 147 | "room.schemaLocation=" + schemaDir.path, |
| 148 | "room.generateKotlin=" + generateKotlin.get() |
| 149 | ] |
Daniel Santiago Rivera | 766b4e3 | 2022-08-10 17:50:44 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
Daniel Santiago Rivera | 4297ec0 | 2023-02-06 16:26:18 -0500 | [diff] [blame^] | 152 | |
| 153 | // KSP does not support argument per flavor so for per flavor options we use flavor named tasks. |
| 154 | // See https://github.com/google/ksp/issues/861. |
| 155 | tasks.withType(KspTask).configureEach { kspTask -> |
| 156 | kspTask.commandLineArgumentProviders.add( |
| 157 | new RoomSchemaArgProvider( |
| 158 | new File(projectDir, "schemas-ksp"), |
| 159 | provider { kspTask.name.contains("GenKotlin") } |
| 160 | ) |
| 161 | ) |
| 162 | } |