xref: /aosp_15_r20/external/moshi/kotlin/tests/codegen-only/build.gradle.kts (revision 238ab3e782f339ab327592a602fa7df0a3f729ad)
1 /*
2  * Copyright (C) 2021 Square, Inc.
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  *    https://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 Build_gradle.TestMode.KAPT
18 import Build_gradle.TestMode.KSP
19 import Build_gradle.TestMode.REFLECT
20 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
21 
<lambda>null22 plugins {
23   kotlin("jvm")
24   kotlin("kapt") apply false
25   id("com.google.devtools.ksp") apply false
26 }
27 
28 enum class TestMode {
29   REFLECT, KAPT, KSP
30 }
31 
32 val testMode = findProperty("kotlinTestMode")?.toString()
33   ?.let(TestMode::valueOf)
34   ?: KSP
35 
36 when (testMode) {
37   REFLECT -> {
38     // Default to KSP. This is a CI-only thing
39     apply(plugin = "com.google.devtools.ksp")
40   }
41   KAPT -> {
42     apply(plugin = "org.jetbrains.kotlin.kapt")
43   }
44   KSP -> {
45     apply(plugin = "com.google.devtools.ksp")
46   }
47 }
48 
<lambda>null49 tasks.withType<Test>().configureEach {
50   // ExtendsPlatformClassWithProtectedField tests a case where we set a protected ByteArrayOutputStream.buf field
51   jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED")
52 }
53 
54 val useWError = findProperty("kotlinLanguageVersion")?.toString()
55   ?.startsWith("1.5")
56   ?: false
<lambda>null57 tasks.withType<KotlinCompile>().configureEach {
58   kotlinOptions {
59     allWarningsAsErrors = useWError
60     @Suppress("SuspiciousCollectionReassignment")
61     freeCompilerArgs += listOf(
62       "-opt-in=kotlin.ExperimentalStdlibApi"
63     )
64   }
65 }
66 
<lambda>null67 dependencies {
68   when (testMode) {
69     REFLECT -> {
70       // Default to KSP in this case, this is a CI-only thing
71       "kspTest"(project(":moshi-kotlin-codegen"))
72     }
73     KAPT -> {
74       "kaptTest"(project(":moshi-kotlin-codegen"))
75     }
76     KSP -> {
77       "kspTest"(project(":moshi-kotlin-codegen"))
78     }
79   }
80   testImplementation(project(":moshi"))
81   testImplementation(project(":moshi-kotlin"))
82   testImplementation(project(":kotlin:tests:extra-moshi-test-module"))
83   testImplementation(kotlin("reflect"))
84   testImplementation(libs.junit)
85   testImplementation(libs.assertj)
86   testImplementation(libs.truth)
87 }
88