blob: 9657ee227ace8393a7e9109a39d669e3145699ea [file] [log] [blame]
Yigit Boyar211efd02020-11-20 11:59:04 -08001/*
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
17import androidx.build.LibraryGroups
18import androidx.build.LibraryType
Yigit Boyar186c4222021-03-01 16:53:38 -080019import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
20
Yigit Boyar211efd02020-11-20 11:59:04 -080021plugins {
22 id("AndroidXPlugin")
23 id("kotlin")
24}
25
26dependencies {
Yigit Boyardeeb7a22020-12-02 21:25:25 -080027 api(project(":room:room-compiler-processing"))
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -070028 implementation(libs.kotlinStdlib)
Aurimas Liutikase1b84582021-04-23 14:17:30 -070029 implementation(libs.kspApi)
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -070030 implementation(libs.kotlinStdlibJdk8) // KSP defines older version as dependency, force update.
Aurimas Liutikase1b84582021-04-23 14:17:30 -070031 implementation(libs.ksp)
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -070032 implementation(libs.googleCompileTesting)
Yigit Boyar6bb8f242021-04-09 16:58:50 -070033 // specify these to match the kotlin compiler version in AndroidX rather than what KSP or KCT
34 // uses
Aurimas Liutikas1a0e7b12021-05-04 12:55:40 -070035 implementation(libs.kotlinCompilerEmbeddable)
36 implementation(libs.kotlinDaemonEmbeddable)
37 implementation(libs.kotlinAnnotationProcessingEmbeddable)
Yigit Boyar211efd02020-11-20 11:59:04 -080038}
39
Yigit Boyar4538d0d2021-01-29 10:25:51 -080040/**
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 */
45def testPropsOutDir = project.layout.buildDirectory.dir("test-config")
46def 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 Liutikasb3483fd2021-06-04 16:56:37 -070052 property("kotlinVersion", libs.versions.kotlin.get())
53 property("kspVersion", libs.versions.ksp.get())
Yigit Boyar4538d0d2021-01-29 10:25:51 -080054}
55
56java {
57 sourceSets {
58 main {
59 resources.srcDir(testPropsOutDir)
60 }
61 }
62}
63
Aurimas Liutikas386ea1d2021-04-29 15:30:34 -070064tasks.named("sourceJar").configure {
65 dependsOn(writeTestPropsTask)
66}
Yigit Boyare0c423c2021-04-01 14:39:30 -070067tasks.named("processResources").configure {
Yigit Boyar4538d0d2021-01-29 10:25:51 -080068 dependsOn(writeTestPropsTask)
69}
Brad Corso48c938e2021-08-06 22:13:31 +000070
71tasks.withType(KotlinCompile).configureEach {
72 kotlinOptions {
73 freeCompilerArgs += [
74 "-Xjvm-default=all",
75 ]
76 }
77}
78
Yigit Boyar186c4222021-03-01 16:53:38 -080079// enable opt in only for tests so that we don't create non experimental APIs by mistake
80// in the source.
81tasks.named("compileTestKotlin", KotlinCompile.class).configure {
82 it.kotlinOptions {
Daniel Santiago Riveraceb65a62021-06-09 10:03:57 -070083 freeCompilerArgs += [
Daniel Santiago Riveraceb65a62021-06-09 10:03:57 -070084 "-Xopt-in=kotlin.RequiresOptIn",
85 "-Xopt-in=androidx.room.compiler.processing.ExperimentalProcessingApi"
86 ]
Yigit Boyar186c4222021-03-01 16:53:38 -080087 }
88}
Yigit Boyar4538d0d2021-01-29 10:25:51 -080089
Yigit Boyar211efd02020-11-20 11:59:04 -080090androidx {
91 name = "AndroidX Room XProcessor Testing"
Yigit Boyar186c4222021-03-01 16:53:38 -080092 type = LibraryType.ANNOTATION_PROCESSOR_UTILS
Yigit Boyar211efd02020-11-20 11:59:04 -080093 mavenGroup = LibraryGroups.ROOM
94 inceptionYear = "2020"
Yigit Boyar211efd02020-11-20 11:59:04 -080095 description = "Testing helpers for Room XProcessing APIs"
96}