xref: /aosp_15_r20/external/kotlinx.coroutines/integration-testing/build.gradle (revision 7a7160fed73afa6648ef8aa100d4a336fe921d9a)
1buildscript {
2
3    /*
4     * These property group is used to build kotlinx.coroutines against Kotlin compiler snapshot.
5     * How does it work:
6     * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
7     * atomicfu_version is overwritten by TeamCity environment (AFU is built with snapshot and published to mavenLocal
8     * as previous step or the snapshot build).
9     * Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled.
10     * DO NOT change the name of these properties without adapting kotlinx.train build chain.
11     */
12    def prop = rootProject.properties['build_snapshot_train']
13    ext.build_snapshot_train = prop != null && prop != ""
14    if (build_snapshot_train) {
15        ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
16        if (kotlin_version == null) {
17            throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
18        }
19    }
20    ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null
21
22    // Determine if any project dependency is using a snapshot version
23    ext.using_snapshot_version = build_snapshot_train
24    rootProject.properties.each { key, value ->
25        if (key.endsWith("_version") && value instanceof String && value.endsWith("-SNAPSHOT")) {
26            println("NOTE: USING SNAPSHOT VERSION: $key=$value")
27            ext.using_snapshot_version = true
28        }
29    }
30
31    if (using_snapshot_version) {
32        repositories {
33            mavenLocal()
34            maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
35        }
36    }
37
38}
39
40plugins {
41    id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
42}
43
44repositories {
45    if (build_snapshot_train) {
46        maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
47    }
48    mavenLocal()
49    mavenCentral()
50}
51
52java {
53    sourceCompatibility = JavaVersion.VERSION_1_8
54    targetCompatibility = JavaVersion.VERSION_1_8
55}
56
57dependencies {
58    testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
59    testImplementation "org.ow2.asm:asm:$asm_version"
60    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
61}
62
63sourceSets {
64    // An assortment of tests for behavior of the core coroutines module on JVM
65    jvmCoreTest {
66        kotlin
67        compileClasspath += sourceSets.test.runtimeClasspath
68        runtimeClasspath += sourceSets.test.runtimeClasspath
69
70        dependencies {
71            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
72            implementation 'com.google.guava:guava:31.1-jre'
73        }
74    }
75    // Checks correctness of Maven publication (JAR resources) and absence of atomicfu symbols
76    mavenTest {
77        kotlin
78        compileClasspath += sourceSets.test.runtimeClasspath
79        runtimeClasspath += sourceSets.test.runtimeClasspath
80
81        dependencies {
82            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
83            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
84        }
85    }
86    // Checks that kotlinx-coroutines-debug can be used as -javaagent parameter
87    debugAgentTest {
88        kotlin
89        compileClasspath += sourceSets.test.runtimeClasspath
90        runtimeClasspath += sourceSets.test.runtimeClasspath
91
92        dependencies {
93            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
94            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutines_version"
95        }
96    }
97
98    // Checks that kotlinx-coroutines-debug agent can self-attach dynamically to JVM as a standalone dependency
99    debugDynamicAgentTest {
100        kotlin
101        compileClasspath += sourceSets.test.runtimeClasspath
102        runtimeClasspath += sourceSets.test.runtimeClasspath
103
104        dependencies {
105            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
106            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutines_version"
107        }
108    }
109
110    // Checks that kotlinx-coroutines-core can be used as -javaagent parameter
111    coreAgentTest {
112        kotlin
113        compileClasspath += sourceSets.test.runtimeClasspath
114        runtimeClasspath += sourceSets.test.runtimeClasspath
115
116        dependencies {
117            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
118        }
119    }
120}
121
122compileDebugAgentTestKotlin {
123    kotlinOptions {
124        freeCompilerArgs += ["-Xallow-kotlin-package"]
125    }
126}
127
128task jvmCoreTest(type: Test) {
129    environment "version", coroutines_version
130    def sourceSet = sourceSets.jvmCoreTest
131    testClassesDirs = sourceSet.output.classesDirs
132    classpath = sourceSet.runtimeClasspath
133}
134
135task mavenTest(type: Test) {
136    environment "version", coroutines_version
137    def sourceSet = sourceSets.mavenTest
138    testClassesDirs = sourceSet.output.classesDirs
139    classpath = sourceSet.runtimeClasspath
140}
141
142task debugAgentTest(type: Test) {
143    def sourceSet = sourceSets.debugAgentTest
144    def coroutinesDebugJar = sourceSet.runtimeClasspath.filter {it.name == "kotlinx-coroutines-debug-${coroutines_version}.jar" }.singleFile
145    jvmArgs ('-javaagent:' + coroutinesDebugJar)
146    testClassesDirs = sourceSet.output.classesDirs
147    classpath = sourceSet.runtimeClasspath
148    systemProperties project.properties.subMap(["overwrite.probes"])
149}
150
151task debugDynamicAgentTest(type: Test) {
152    def sourceSet = sourceSets.debugDynamicAgentTest
153    testClassesDirs = sourceSet.output.classesDirs
154    classpath = sourceSet.runtimeClasspath
155}
156
157task coreAgentTest(type: Test) {
158    def sourceSet = sourceSets.coreAgentTest
159    def coroutinesCoreJar = sourceSet.runtimeClasspath.filter {it.name == "kotlinx-coroutines-core-jvm-${coroutines_version}.jar" }.singleFile
160    jvmArgs ('-javaagent:' + coroutinesCoreJar)
161    testClassesDirs = sourceSet.output.classesDirs
162    classpath = sourceSet.runtimeClasspath
163}
164
165compileTestKotlin {
166    kotlinOptions.jvmTarget = "1.8"
167}
168
169check {
170    dependsOn([jvmCoreTest, debugDynamicAgentTest, mavenTest, debugAgentTest, coreAgentTest, 'smokeTest:build'])
171}
172compileKotlin {
173    kotlinOptions {
174        jvmTarget = "1.8"
175    }
176}
177
178// Drop this when node js version become stable
179tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask.class).configureEach {
180    it.args.add("--ignore-engines")
181}
182