Yigit Boyar | 211efd0 | 2020-11-20 11:59:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | */ |
| 16 | |
| 17 | import androidx.build.LibraryGroups |
| 18 | import androidx.build.LibraryType |
Yigit Boyar | 186c422 | 2021-03-01 16:53:38 -0800 | [diff] [blame] | 19 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| 20 | |
Yigit Boyar | 211efd0 | 2020-11-20 11:59:04 -0800 | [diff] [blame] | 21 | plugins { |
| 22 | id("AndroidXPlugin") |
| 23 | id("kotlin") |
| 24 | } |
| 25 | |
| 26 | dependencies { |
Yigit Boyar | deeb7a2 | 2020-12-02 21:25:25 -0800 | [diff] [blame] | 27 | api(project(":room:room-compiler-processing")) |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 28 | implementation(libs.kotlinStdlib) |
Aurimas Liutikas | e1b8458 | 2021-04-23 14:17:30 -0700 | [diff] [blame] | 29 | implementation(libs.kspApi) |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 30 | implementation(libs.kotlinStdlibJdk8) // KSP defines older version as dependency, force update. |
Aurimas Liutikas | e1b8458 | 2021-04-23 14:17:30 -0700 | [diff] [blame] | 31 | implementation(libs.ksp) |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 32 | implementation(libs.googleCompileTesting) |
Yigit Boyar | 6bb8f24 | 2021-04-09 16:58:50 -0700 | [diff] [blame] | 33 | // specify these to match the kotlin compiler version in AndroidX rather than what KSP or KCT |
| 34 | // uses |
Aurimas Liutikas | 1a0e7b1 | 2021-05-04 12:55:40 -0700 | [diff] [blame] | 35 | implementation(libs.kotlinCompilerEmbeddable) |
| 36 | implementation(libs.kotlinDaemonEmbeddable) |
| 37 | implementation(libs.kotlinAnnotationProcessingEmbeddable) |
Yigit Boyar | 211efd0 | 2020-11-20 11:59:04 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Yigit Boyar | 4538d0d | 2021-01-29 10:25:51 -0800 | [diff] [blame] | 40 | /** |
| 41 | * Create a properties file with versions that can be read from the test helper to setup test |
| 42 | * projects. |
| 43 | * see: b/178725084 |
| 44 | */ |
| 45 | def testPropsOutDir = project.layout.buildDirectory.dir("test-config") |
| 46 | def writeTestPropsTask = tasks.register("prepareTestConfiguration", WriteProperties.class) { |
| 47 | description = "Generates a properties file with the current environment for compilation tests" |
| 48 | setOutputFile(testPropsOutDir.map { |
| 49 | it.file("androidx.room.compiler.processing.util.CompilationTestCapabilities.Config" + |
| 50 | ".properties") |
| 51 | }) |
Aurimas Liutikas | b3483fd | 2021-06-04 16:56:37 -0700 | [diff] [blame] | 52 | property("kotlinVersion", libs.versions.kotlin.get()) |
| 53 | property("kspVersion", libs.versions.ksp.get()) |
Yigit Boyar | 4538d0d | 2021-01-29 10:25:51 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | java { |
| 57 | sourceSets { |
| 58 | main { |
| 59 | resources.srcDir(testPropsOutDir) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
Aurimas Liutikas | 386ea1d | 2021-04-29 15:30:34 -0700 | [diff] [blame] | 64 | tasks.named("sourceJar").configure { |
| 65 | dependsOn(writeTestPropsTask) |
| 66 | } |
Yigit Boyar | e0c423c | 2021-04-01 14:39:30 -0700 | [diff] [blame] | 67 | tasks.named("processResources").configure { |
Yigit Boyar | 4538d0d | 2021-01-29 10:25:51 -0800 | [diff] [blame] | 68 | dependsOn(writeTestPropsTask) |
| 69 | } |
Brad Corso | 48c938e | 2021-08-06 22:13:31 +0000 | [diff] [blame] | 70 | |
| 71 | tasks.withType(KotlinCompile).configureEach { |
| 72 | kotlinOptions { |
| 73 | freeCompilerArgs += [ |
| 74 | "-Xjvm-default=all", |
| 75 | ] |
| 76 | } |
| 77 | } |
| 78 | |
Yigit Boyar | 186c422 | 2021-03-01 16:53:38 -0800 | [diff] [blame] | 79 | // enable opt in only for tests so that we don't create non experimental APIs by mistake |
| 80 | // in the source. |
| 81 | tasks.named("compileTestKotlin", KotlinCompile.class).configure { |
| 82 | it.kotlinOptions { |
Daniel Santiago Rivera | ceb65a6 | 2021-06-09 10:03:57 -0700 | [diff] [blame] | 83 | freeCompilerArgs += [ |
Daniel Santiago Rivera | ceb65a6 | 2021-06-09 10:03:57 -0700 | [diff] [blame] | 84 | "-Xopt-in=kotlin.RequiresOptIn", |
| 85 | "-Xopt-in=androidx.room.compiler.processing.ExperimentalProcessingApi" |
| 86 | ] |
Yigit Boyar | 186c422 | 2021-03-01 16:53:38 -0800 | [diff] [blame] | 87 | } |
| 88 | } |
Yigit Boyar | 4538d0d | 2021-01-29 10:25:51 -0800 | [diff] [blame] | 89 | |
Yigit Boyar | 211efd0 | 2020-11-20 11:59:04 -0800 | [diff] [blame] | 90 | androidx { |
| 91 | name = "AndroidX Room XProcessor Testing" |
Yigit Boyar | 186c422 | 2021-03-01 16:53:38 -0800 | [diff] [blame] | 92 | type = LibraryType.ANNOTATION_PROCESSOR_UTILS |
Yigit Boyar | 211efd0 | 2020-11-20 11:59:04 -0800 | [diff] [blame] | 93 | mavenGroup = LibraryGroups.ROOM |
| 94 | inceptionYear = "2020" |
Yigit Boyar | 211efd0 | 2020-11-20 11:59:04 -0800 | [diff] [blame] | 95 | description = "Testing helpers for Room XProcessing APIs" |
| 96 | } |