xref: /aosp_15_r20/external/moshi/kotlin/tests/build.gradle.kts (revision 238ab3e782f339ab327592a602fa7df0a3f729ad)
1 /*
2  * Copyright (C) 2020 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   ?: REFLECT
35 
36 when (testMode) {
37   REFLECT -> {
38     // Do nothing!
39   }
40   KAPT -> {
41     apply(plugin = "org.jetbrains.kotlin.kapt")
42   }
43   KSP -> {
44     apply(plugin = "com.google.devtools.ksp")
45   }
46 }
47 
<lambda>null48 tasks.withType<Test>().configureEach {
49   // ExtendsPlatformClassWithProtectedField tests a case where we set a protected ByteArrayOutputStream.buf field
50   jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED")
51 }
52 
53 val useWError = findProperty("kotlinLanguageVersion")?.toString()
54   ?.startsWith("1.5")
55   ?: false
<lambda>null56 tasks.withType<KotlinCompile>().configureEach {
57   kotlinOptions {
58     allWarningsAsErrors = useWError
59     @Suppress("SuspiciousCollectionReassignment")
60     freeCompilerArgs += listOf(
61       "-opt-in=kotlin.ExperimentalStdlibApi"
62     )
63   }
64 }
65 
<lambda>null66 dependencies {
67   when (testMode) {
68     REFLECT -> {
69       // Do nothing
70     }
71     KAPT -> {
72       "kaptTest"(project(":moshi-kotlin-codegen"))
73     }
74     KSP -> {
75       "kspTest"(project(":moshi-kotlin-codegen"))
76     }
77   }
78   testImplementation(project(":moshi"))
79   testImplementation(project(":moshi-kotlin"))
80   testImplementation(project(":kotlin:tests:extra-moshi-test-module"))
81   testImplementation(kotlin("reflect"))
82   testImplementation(libs.junit)
83   testImplementation(libs.assertj)
84   testImplementation(libs.truth)
85 }
86