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