blob: 158051af7e7972e9f4ed93eccae82e0bc8a24d33 [file] [log] [blame]
Florina Muntenescu34f575b2017-07-17 10:38:50 +01001/*
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 Boyar1f8acf72018-02-08 13:05:00 -080016// 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 Lamc351bfc2020-03-11 20:32:42 -070020
Daniel Santiago Rivera766b4e32022-08-10 17:50:44 -070021import com.google.devtools.ksp.gradle.KspTask
Dustin Lamc351bfc2020-03-11 20:32:42 -070022
Aurimas Liutikas238e4802017-12-14 10:52:11 -080023plugins {
Aurimas Liutikas21ff5d12018-08-15 15:33:13 -070024 id("AndroidXPlugin")
25 id("com.android.application")
Aurimas Liutikas238e4802017-12-14 10:52:11 -080026 id("kotlin-android")
Yigit Boyar315ae402021-07-14 22:07:56 -070027 // both ksp and kapt are applied. each run in their own variant.
28 id("com.google.devtools.ksp")
29 id("kotlin-kapt")
Yigit Boyar23758df2020-12-16 18:47:29 -080030}
Florina Muntenescu34f575b2017-07-17 10:38:50 +010031android {
Yigit Boyaraf110fe2021-01-14 22:53:42 -080032 buildFeatures {
33 buildConfig = true
34 }
Florina Muntenescu34f575b2017-07-17 10:38:50 +010035 defaultConfig {
Yigit Boyar04b04742021-02-26 12:04:07 -080036 multiDexEnabled true
Florina Muntenescu34f575b2017-07-17 10:38:50 +010037 javaCompileOptions {
38 annotationProcessorOptions {
Yigit Boyar60b74ae2020-03-10 17:02:50 -070039 arguments = [
Yigit Boyar315ae402021-07-14 22:07:56 -070040 "room.schemaLocation" : "$projectDir/schemas".toString()
Yigit Boyar60b74ae2020-03-10 17:02:50 -070041 ]
Florina Muntenescu34f575b2017-07-17 10:38:50 +010042 }
43 }
44 }
Dustin Lamc351bfc2020-03-11 20:32:42 -070045
Florina Muntenescu34f575b2017-07-17 10:38:50 +010046 sourceSets {
Yigit Boyar315ae402021-07-14 22:07:56 -070047 androidTestWithKapt.assets.srcDirs += files("$projectDir/schemas".toString())
Daniel Santiago Rivera766b4e32022-08-10 17:50:44 -070048 androidTestWithKspGenJava.assets.srcDirs += files("$projectDir/schemas-ksp".toString())
49 androidTestWithKspGenKotlin.assets.srcDirs += files("$projectDir/schemas-ksp".toString())
Florina Muntenescu34f575b2017-07-17 10:38:50 +010050 }
Yigit Boyar71103042020-04-06 17:28:21 -070051
Jeff Gastonff3f1b22020-08-04 11:24:37 -040052 flavorDimensions "processorConfiguration"
53 productFlavors {
Yigit Boyar315ae402021-07-14 22:07:56 -070054 withKapt {
Jeff Gastonff3f1b22020-08-04 11:24:37 -040055 dimension "processorConfiguration"
56 javaCompileOptions {
57 annotationProcessorOptions {
58 arguments = [
59 "room.schemaLocation" : "$projectDir/schemas".toString(),
Jeff Gastonff3f1b22020-08-04 11:24:37 -040060 ]
61 }
62 }
63 }
Daniel Santiago Rivera766b4e32022-08-10 17:50:44 -070064 withKspGenJava {
65 dimension "processorConfiguration"
66 }
67 withKspGenKotlin {
Jeff Gastonff3f1b22020-08-04 11:24:37 -040068 dimension "processorConfiguration"
Jeff Gastonff3f1b22020-08-04 11:24:37 -040069 }
70 }
Aurimas Liutikasdcfa0352022-03-14 16:05:33 -070071 namespace "androidx.room.integration.kotlintestapp"
Florina Muntenescu34f575b2017-07-17 10:38:50 +010072}
73
74dependencies {
Alan Viverette6c563342018-03-08 18:02:39 -050075 implementation(project(":room:room-common"))
Alan Viverette6c563342018-03-08 18:02:39 -050076 implementation(project(":room:room-runtime"))
Clara Fok22eccb92021-06-15 16:32:01 -070077 implementation(project(":room:room-paging"))
Dustin Lam1b2b8e22020-11-19 00:39:04 +000078 implementation(projectOrArtifact(":arch:core:core-runtime"))
Yigit Boyara755f332020-05-30 19:14:46 -070079 implementation(projectOrArtifact(":lifecycle:lifecycle-livedata"))
Yigit Boyaraf110fe2021-01-14 22:53:42 -080080 implementation(projectOrArtifact(":lifecycle:lifecycle-livedata-ktx"))
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -070081 implementation(libs.kotlinStdlib)
82 implementation(libs.kotlinCoroutinesAndroid)
83 implementation(libs.multidex)
Yigit Boyar562a37d2020-03-16 13:00:36 -070084 // depend on the shadowed version so that it tests with the shipped artifact
Yigit Boyar23758df2020-12-16 18:47:29 -080085 // this is a temporary attribute until KSP and AndroidX plugin supports variants.
Daniel Santiago Rivera766b4e32022-08-10 17:50:44 -070086 kspAndroidTestWithKspGenJava(
87 project(path: ":room:room-compiler", configuration: "shadowAndImplementation")
88 )
89 kspAndroidTestWithKspGenKotlin(
Yigit Boyar315ae402021-07-14 22:07:56 -070090 project(path: ":room:room-compiler", configuration: "shadowAndImplementation")
91 )
92 kaptAndroidTestWithKapt(
93 project(path: ":room:room-compiler", configuration: "shadowAndImplementation")
94 )
Aurimas Liutikascb841c52021-04-01 14:14:10 -070095 androidTestImplementation(projectOrArtifact(":lifecycle:lifecycle-livedata-ktx"))
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -070096 androidTestImplementation(libs.testExtJunit)
97 androidTestImplementation(libs.testCore)
98 androidTestImplementation(libs.testRunner) {
Jim Sproch9e38b4f2021-01-06 14:21:06 -080099 exclude module: "support-annotations"
100 exclude module: "hamcrest-core"
Florina Muntenescu34f575b2017-07-17 10:38:50 +0100101 }
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -0700102 androidTestImplementation(libs.espressoCore, {
Jim Sproch9e38b4f2021-01-06 14:21:06 -0800103 exclude group: "com.android.support", module: "support-annotations"
Florina Muntenescu34f575b2017-07-17 10:38:50 +0100104 exclude module: "hamcrest-core"
105 })
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -0700106 androidTestImplementation(libs.truth)
Clara Fok22eccb92021-06-15 16:32:01 -0700107 androidTestImplementation(libs.kotlinTest)
Jim Sproch9e38b4f2021-01-06 14:21:06 -0800108 androidTestImplementation(project(":room:room-guava"))
109 androidTestImplementation(project(":room:room-testing"))
Clara Fok76e8c1e2022-04-28 17:05:24 -0700110 androidTestImplementation(project(":room:room-paging-guava"))
clarafokd1ba5792022-05-13 16:09:09 -0700111 androidTestImplementation(project(":room:room-paging-rxjava2"))
clarafokc7b01e92022-05-12 15:28:45 -0700112 androidTestImplementation(project(":room:room-paging-rxjava3"))
Clara Fok76e8c1e2022-04-28 17:05:24 -0700113 // 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 Sproch9e38b4f2021-01-06 14:21:06 -0800116 androidTestImplementation(project(":room:room-rxjava2"))
Yigit Boyaraf110fe2021-01-14 22:53:42 -0800117 androidTestImplementation(project(":room:room-rxjava3"))
Daniel Santiago Rivera1fc19602019-02-27 15:48:32 -0800118 androidTestImplementation(project(":room:room-ktx"))
Clara Fok583863d2021-08-18 18:28:43 -0700119 androidTestImplementation(project(":internal-testutils-common"))
Ian Lake005a9202019-09-26 16:17:25 -0700120 androidTestImplementation("androidx.arch.core:core-testing:2.0.1")
Dustin Lamcd9288e2022-04-21 15:33:51 -0700121 androidTestImplementation("androidx.paging:paging-runtime:3.1.1")
Dustin Lam45c49782022-08-22 19:11:59 +0000122 androidTestImplementation(projectOrArtifact(":lifecycle:lifecycle-runtime-testing"))
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -0700123 androidTestImplementation(libs.rxjava2)
David Saff33823622022-09-08 09:45:19 -0400124 androidTestImplementation(libs.kotlinCoroutinesTest)
Aurimas Liutikas759f9682022-10-05 07:01:37 -0700125 testImplementation(libs.mockitoCore4)
Florina Muntenescu34f575b2017-07-17 10:38:50 +0100126}
127
Daniel Santiago Rivera4297ec02023-02-06 16:26:18 -0500128class RoomSchemaArgProvider implements CommandLineArgumentProvider {
Jim Sproch3f742d52023-02-02 13:41:33 -0800129
Daniel Santiago Rivera4297ec02023-02-06 16:26:18 -0500130 @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 Rivera766b4e32022-08-10 17:50:44 -0700150 }
151}
Daniel Santiago Rivera4297ec02023-02-06 16:26:18 -0500152
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.
155tasks.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}