| Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 1 | /* | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 2 | * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | 
| Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 3 | */ | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 4 | import org.jetbrains.kotlin.konan.target.HostManager | 
|  | 5 |  | 
|  | 6 | apply from: rootProject.file("gradle/experimental.gradle") | 
|  | 7 |  | 
|  | 8 | def rootModule = "kotlinx.coroutines" | 
|  | 9 | def coreModule = "kotlinx-coroutines-core" | 
|  | 10 | // Not applicable for Kotlin plugin | 
|  | 11 | def sourceless = ['kotlinx.coroutines', 'site'] | 
|  | 12 | def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator'] | 
|  | 13 | // Not published | 
|  | 14 | def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'android-unit-tests'] | 
|  | 15 |  | 
|  | 16 | static def platformOf(project) { | 
|  | 17 | def name = project.name | 
|  | 18 | if (name.endsWith("-js")) return "js" | 
|  | 19 | if (name.endsWith("-common") || name.endsWith("-native")) { | 
|  | 20 | throw IllegalStateException("$name platform is not supported") | 
|  | 21 | } | 
|  | 22 | return "jvm" | 
|  | 23 | } | 
| Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame] | 24 |  | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 25 | buildscript { | 
| Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 26 | /* | 
|  | 27 | * These property group is used to build kotlinx.coroutines against Kotlin compiler snapshot. | 
|  | 28 | * How does it work: | 
|  | 29 | * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version, | 
|  | 30 | * atomicfu_version is overwritten by TeamCity environment (AFU is built with snapshot and published to mavenLocal | 
|  | 31 | * as previous step or the snapshot build). | 
|  | 32 | * Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled. | 
|  | 33 | * DO NOT change the name of these properties without adapting kotlinx.train build chain. | 
|  | 34 | */ | 
|  | 35 | def prop = rootProject.properties['build_snapshot_train'] | 
|  | 36 | ext.build_snapshot_train = prop != null && prop != "" | 
|  | 37 | if (build_snapshot_train) { | 
|  | 38 | ext.kotlin_version = rootProject.properties['kotlin_snapshot_version'] | 
|  | 39 | if (kotlin_version == null) { | 
|  | 40 | throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler") | 
|  | 41 | } | 
| Roman Elizarov | 1f6b44d | 2017-10-26 17:51:52 +0300 | [diff] [blame] | 42 | repositories { | 
| Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 43 | mavenLocal() | 
| Roman Elizarov | 1f6b44d | 2017-10-26 17:51:52 +0300 | [diff] [blame] | 44 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } | 
|  | 45 | } | 
|  | 46 | } | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 47 | repositories { | 
|  | 48 | jcenter() | 
| Roman Elizarov | 3145290 | 2018-04-11 13:58:19 +0300 | [diff] [blame] | 49 | maven { url "https://kotlin.bintray.com/kotlinx" } | 
|  | 50 | maven { url "https://kotlin.bintray.com/kotlin-dev" } | 
| Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 51 | maven { url "https://kotlin.bintray.com/kotlin-eap" } | 
| Roman Elizarov | 3145290 | 2018-04-11 13:58:19 +0300 | [diff] [blame] | 52 | maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" } | 
| Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 53 | maven { url "https://plugins.gradle.org/m2/" } | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 54 | } | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 55 |  | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 56 | dependencies { | 
| Vsevolod Tolstopyatov | 3179683 | 2018-11-12 14:49:41 +0300 | [diff] [blame] | 57 | classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$artifactory_plugin_version" | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 58 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | 
|  | 59 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" | 
| Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 60 | classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version" | 
| Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 61 | classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version" | 
|  | 62 | classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version" | 
| Vsevolod Tolstopyatov | 305c66a | 2018-08-21 21:01:58 +0300 | [diff] [blame] | 63 |  | 
|  | 64 | // JMH plugins | 
| Vsevolod Tolstopyatov | 3781a82 | 2018-12-13 11:58:29 +0300 | [diff] [blame] | 65 | classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2" | 
| Vsevolod Tolstopyatov | 305c66a | 2018-08-21 21:01:58 +0300 | [diff] [blame] | 66 | classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.7" | 
|  | 67 | classpath "net.ltgt.gradle:gradle-apt-plugin:0.10" | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 68 | } | 
|  | 69 | } | 
|  | 70 |  | 
| Ilya Gorbunov | b1a07ee | 2018-04-16 21:51:55 +0300 | [diff] [blame] | 71 | allprojects { | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 72 | // the only place where HostManager could be instantiated | 
|  | 73 | project.ext.hostManager = new HostManager() | 
| Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 74 | def deployVersion = properties['DeployVersion'] | 
|  | 75 | if (deployVersion != null) version = deployVersion | 
|  | 76 |  | 
|  | 77 | if (build_snapshot_train) { | 
|  | 78 | ext.kotlin_version = rootProject.properties['kotlin_snapshot_version'] | 
|  | 79 | println "Using Kotlin $kotlin_version for project $it" | 
|  | 80 |  | 
|  | 81 | if (version != atomicfu_version) { | 
|  | 82 | throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it") | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | kotlin_version = rootProject.properties['kotlin_snapshot_version'] | 
|  | 86 | repositories { | 
|  | 87 | mavenLocal() | 
|  | 88 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } | 
|  | 89 | } | 
|  | 90 | } | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
|  | 93 | allprojects { | 
|  | 94 | apply plugin: 'kotlinx-atomicfu' | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 95 | def projectName = it.name | 
| Roman Elizarov | 18fa116 | 2018-06-27 15:13:01 +0300 | [diff] [blame] | 96 | repositories { | 
| Vsevolod Tolstopyatov | 6f01c93 | 2018-10-23 19:40:48 +0300 | [diff] [blame] | 97 | /* | 
|  | 98 | * google should be first in the repository list because some of the play services | 
|  | 99 | * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution | 
|  | 100 | */ | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 101 | if (projectName == "kotlinx-coroutines-play-services") { | 
| Vsevolod Tolstopyatov | 6f01c93 | 2018-10-23 19:40:48 +0300 | [diff] [blame] | 102 | google() | 
|  | 103 | } | 
| Roman Elizarov | 18fa116 | 2018-06-27 15:13:01 +0300 | [diff] [blame] | 104 | jcenter() | 
| Vsevolod Tolstopyatov | 8a45c47 | 2018-10-24 11:55:30 +0300 | [diff] [blame] | 105 | maven { url "https://kotlin.bintray.com/kotlin-dev" } | 
| Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 106 | maven { url "https://kotlin.bintray.com/kotlin-eap" } | 
| Roman Elizarov | 18fa116 | 2018-06-27 15:13:01 +0300 | [diff] [blame] | 107 | maven { url "https://kotlin.bintray.com/kotlinx" } | 
|  | 108 | } | 
| Ilya Gorbunov | b1a07ee | 2018-04-16 21:51:55 +0300 | [diff] [blame] | 109 |  | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 110 | if (projectName == rootModule || projectName == coreModule) return | 
| Ilya Gorbunov | b1a07ee | 2018-04-16 21:51:55 +0300 | [diff] [blame] | 111 |  | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 112 | // Add dependency to core source sets. Core is configured in kx-core/build.gradle | 
|  | 113 | evaluationDependsOn(":$coreModule") | 
|  | 114 | if (sourceless.contains(projectName)) return | 
| Roman Elizarov | 38b6fd3 | 2018-01-17 10:12:23 +0300 | [diff] [blame] | 115 |  | 
| Roman Elizarov | e1c0b65 | 2017-12-01 14:02:57 +0300 | [diff] [blame] | 116 | def platform = platformOf(it) | 
| Roman Elizarov | e1a5652 | 2018-04-04 10:31:08 +0300 | [diff] [blame] | 117 | apply from: rootProject.file("gradle/compile-${platform}.gradle") | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 118 |  | 
|  | 119 |  | 
|  | 120 | dependencies { | 
|  | 121 | // See comment below for rationale, it will be replaced with "project" dependency | 
|  | 122 | compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version" | 
| Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 123 | compileOnly "org.jetbrains.kotlinx:atomicfu:$atomicfu_version" | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 124 |  | 
|  | 125 | // the only way IDEA can resolve test classes | 
|  | 126 | testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all { | 
|  | 130 | kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it } | 
|  | 131 | kotlinOptions.freeCompilerArgs += "-progressive" | 
|  | 132 | // Binary compatibility support | 
|  | 133 | kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"] | 
|  | 134 | } | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
| Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 137 | if (build_snapshot_train) { | 
|  | 138 | println "Hacking test tasks, removing stress and flaky tests" | 
|  | 139 | allprojects { | 
|  | 140 | tasks.withType(Test).all { | 
| Vsevolod Tolstopyatov | dbe3f48 | 2019-04-17 17:51:13 +0300 | [diff] [blame] | 141 | exclude '**/*LinearizabilityTest*' | 
|  | 142 | exclude '**/*LFTest*' | 
|  | 143 | exclude '**/*StressTest*' | 
|  | 144 | exclude '**/*scheduling*' | 
|  | 145 | exclude '**/*Timeout*' | 
| Vsevolod Tolstopyatov | 1748ce1 | 2019-04-18 14:49:35 +0300 | [diff] [blame^] | 146 | exclude '**/*coroutines/debug*' // Unmute after 1.3.31 where inlining was fixed | 
|  | 147 | exclude '**/*definitely/not/kotlinx*' | 
|  | 148 | } | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | println "Manifest of kotlin-compiler-embeddable.jar for coroutines" | 
|  | 152 | configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) { | 
|  | 153 | configurations.matching { it.name == "kotlinCompilerClasspath" }.all { | 
|  | 154 | resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each { | 
|  | 155 | def manifest = zipTree(it).matching { | 
|  | 156 | include 'META-INF/MANIFEST.MF' | 
|  | 157 | }.getFiles().first() | 
|  | 158 |  | 
|  | 159 | manifest.readLines().each { | 
|  | 160 | println it | 
|  | 161 | } | 
|  | 162 | } | 
| Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 163 | } | 
|  | 164 | } | 
|  | 165 | } | 
|  | 166 |  | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 167 | /* | 
|  | 168 | * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies, | 
|  | 169 | * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files | 
|  | 170 | * for JVM-only projects. | 
|  | 171 | * | 
|  | 172 | * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it | 
|  | 173 | * to have out "project" dependency back. | 
|  | 174 | */ | 
|  | 175 | configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) { | 
|  | 176 | configurations.all { | 
|  | 177 | resolutionStrategy.dependencySubstitution { | 
|  | 178 | substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core') | 
|  | 179 | } | 
|  | 180 | } | 
|  | 181 | } | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 182 |  | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 183 | // Redefine source sets because we are not using 'kotlin/main/fqn' folder convention | 
|  | 184 | configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) { | 
| Vsevolod Tolstopyatov | e1fa197 | 2018-06-19 15:54:58 +0300 | [diff] [blame] | 185 | sourceSets { | 
| Roman Elizarov | f9408f6 | 2018-06-29 20:12:52 +0300 | [diff] [blame] | 186 | main.kotlin.srcDirs = ['src'] | 
|  | 187 | test.kotlin.srcDirs = ['test'] | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 188 | main.resources.srcDirs = ['resources'] | 
|  | 189 | test.resources.srcDirs = ['test-resources'] | 
| Vsevolod Tolstopyatov | e1fa197 | 2018-06-19 15:54:58 +0300 | [diff] [blame] | 190 | } | 
|  | 191 | } | 
|  | 192 |  | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 193 | def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/" | 
|  | 194 | def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list" | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 195 |  | 
|  | 196 | configure(subprojects.findAll { !unpublished.contains(it.name) }) { | 
| Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 197 | apply from: rootProject.file('gradle/dokka.gradle') | 
|  | 198 | apply from: rootProject.file('gradle/publish-bintray.gradle') | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
| Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 201 | configure(subprojects.findAll { !unpublished.contains(it.name) }) { | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 202 | if (it.name != coreModule) { | 
|  | 203 | dokka.dependsOn project(":$coreModule").dokka | 
| Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 204 | tasks.withType(dokka.getClass()) { | 
|  | 205 | externalDocumentationLink { | 
|  | 206 | url = new URL(core_docs_url) | 
|  | 207 | packageListUrl = new URL("file://$core_docs_file") | 
|  | 208 | } | 
|  | 209 | } | 
|  | 210 | } | 
| Vsevolod Tolstopyatov | e6e8239 | 2018-10-09 19:06:29 +0300 | [diff] [blame] | 211 |  | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 212 | if (platformOf(it) == "jvm") { | 
|  | 213 | dokkaJavadoc.dependsOn project(":$coreModule").dokka | 
| Vsevolod Tolstopyatov | e6e8239 | 2018-10-09 19:06:29 +0300 | [diff] [blame] | 214 | } | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 215 | } | 
|  | 216 |  | 
| Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 217 | // Report Kotlin compiler version when building project | 
|  | 218 | println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION") | 
|  | 219 |  | 
|  | 220 | // --------------- Configure sub-projects that are published --------------- | 
| Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 221 | task deploy(dependsOn: getTasksByName("bintrayUpload", true) + getTasksByName("publishNpm", true)) | 
|  | 222 |  | 
| Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 223 | apply plugin: 'base' | 
|  | 224 |  | 
|  | 225 | clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') } |