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 |
Vsevolod Tolstopyatov | fe4e05c | 2019-07-19 12:28:15 +0300 | [diff] [blame] | 11 | def sourceless = ['kotlinx.coroutines', 'site', 'kotlinx-coroutines-bom'] |
| 12 | def internal = ['kotlinx.coroutines', 'site', 'benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator'] |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 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 | e1ac2e5 | 2019-04-19 18:51:05 +0300 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT")) { |
Roman Elizarov | 1f6b44d | 2017-10-26 17:51:52 +0300 | [diff] [blame] | 45 | repositories { |
Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 46 | mavenLocal() |
Roman Elizarov | 1f6b44d | 2017-10-26 17:51:52 +0300 | [diff] [blame] | 47 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } |
| 48 | } |
| 49 | } |
Roman Elizarov | e1ac2e5 | 2019-04-19 18:51:05 +0300 | [diff] [blame] | 50 | |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 51 | repositories { |
| 52 | jcenter() |
Roman Elizarov | 3145290 | 2018-04-11 13:58:19 +0300 | [diff] [blame] | 53 | maven { url "https://kotlin.bintray.com/kotlinx" } |
| 54 | maven { url "https://kotlin.bintray.com/kotlin-dev" } |
Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 55 | maven { url "https://kotlin.bintray.com/kotlin-eap" } |
Roman Elizarov | 3145290 | 2018-04-11 13:58:19 +0300 | [diff] [blame] | 56 | maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" } |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 57 | maven { url "https://plugins.gradle.org/m2/" } |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 58 | } |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 59 | |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 60 | dependencies { |
| 61 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 62 | classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" |
Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 63 | classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version" |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 64 | classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version" |
Vsevolod Tolstopyatov | fe4e05c | 2019-07-19 12:28:15 +0300 | [diff] [blame] | 65 | classpath "io.spring.gradle:dependency-management-plugin:$spring_dependency_management_version" |
Vsevolod Tolstopyatov | 305c66a | 2018-08-21 21:01:58 +0300 | [diff] [blame] | 66 | |
| 67 | // JMH plugins |
Vsevolod Tolstopyatov | bda9c79 | 2019-09-12 16:50:33 +0300 | [diff] [blame^] | 68 | classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0" |
| 69 | classpath "me.champeau.gradle:jmh-gradle-plugin:0.5.0-rc-2" |
| 70 | classpath "net.ltgt.gradle:gradle-apt-plugin:0.21" |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 74 | import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType |
| 75 | |
| 76 | // todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules |
| 77 | def configureKotlinJvmPlatform(configuration) { |
| 78 | configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) |
| 79 | } |
| 80 | |
Ilya Gorbunov | b1a07ee | 2018-04-16 21:51:55 +0300 | [diff] [blame] | 81 | allprojects { |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 82 | // the only place where HostManager could be instantiated |
| 83 | project.ext.hostManager = new HostManager() |
Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 84 | def deployVersion = properties['DeployVersion'] |
| 85 | if (deployVersion != null) version = deployVersion |
| 86 | |
| 87 | if (build_snapshot_train) { |
| 88 | ext.kotlin_version = rootProject.properties['kotlin_snapshot_version'] |
| 89 | println "Using Kotlin $kotlin_version for project $it" |
| 90 | |
Vsevolod Tolstopyatov | 6ca6ed5 | 2019-08-21 17:08:34 +0300 | [diff] [blame] | 91 | def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null |
| 92 | if (!skipSnapshotChecks && version != atomicfu_version) { |
Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 93 | throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it") |
| 94 | } |
| 95 | |
| 96 | kotlin_version = rootProject.properties['kotlin_snapshot_version'] |
Roman Elizarov | e1ac2e5 | 2019-04-19 18:51:05 +0300 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT")) { |
Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 100 | repositories { |
| 101 | mavenLocal() |
| 102 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } |
| 103 | } |
| 104 | } |
Vsevolod Tolstopyatov | fe4e05c | 2019-07-19 12:28:15 +0300 | [diff] [blame] | 105 | |
| 106 | ext.unpublished = unpublished |
Roman Elizarov | 0b16abf | 2019-09-03 11:07:11 +0300 | [diff] [blame] | 107 | |
| 108 | // This project property is set during nightly stress test |
| 109 | def stressTest = project.properties['stressTest'] |
| 110 | |
| 111 | // Copy it to all test tasks |
| 112 | tasks.withType(Test) { |
| 113 | systemProperty 'stressTest', stressTest |
| 114 | } |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | allprojects { |
Roman Elizarov | e1ac2e5 | 2019-04-19 18:51:05 +0300 | [diff] [blame] | 118 | apply plugin: 'kotlinx-atomicfu' // it also adds all the necessary dependencies |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 119 | def projectName = it.name |
Roman Elizarov | 18fa116 | 2018-06-27 15:13:01 +0300 | [diff] [blame] | 120 | repositories { |
Vsevolod Tolstopyatov | 6f01c93 | 2018-10-23 19:40:48 +0300 | [diff] [blame] | 121 | /* |
| 122 | * google should be first in the repository list because some of the play services |
| 123 | * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution |
| 124 | */ |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 125 | if (projectName == "kotlinx-coroutines-play-services") { |
Vsevolod Tolstopyatov | 6f01c93 | 2018-10-23 19:40:48 +0300 | [diff] [blame] | 126 | google() |
| 127 | } |
Roman Elizarov | 18fa116 | 2018-06-27 15:13:01 +0300 | [diff] [blame] | 128 | jcenter() |
Vsevolod Tolstopyatov | 8a45c47 | 2018-10-24 11:55:30 +0300 | [diff] [blame] | 129 | maven { url "https://kotlin.bintray.com/kotlin-dev" } |
Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 130 | maven { url "https://kotlin.bintray.com/kotlin-eap" } |
Roman Elizarov | 18fa116 | 2018-06-27 15:13:01 +0300 | [diff] [blame] | 131 | maven { url "https://kotlin.bintray.com/kotlinx" } |
| 132 | } |
Ilya Gorbunov | b1a07ee | 2018-04-16 21:51:55 +0300 | [diff] [blame] | 133 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 134 | if (projectName == rootModule || projectName == coreModule) return |
Ilya Gorbunov | b1a07ee | 2018-04-16 21:51:55 +0300 | [diff] [blame] | 135 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 136 | // Add dependency to core source sets. Core is configured in kx-core/build.gradle |
| 137 | evaluationDependsOn(":$coreModule") |
| 138 | if (sourceless.contains(projectName)) return |
Roman Elizarov | 38b6fd3 | 2018-01-17 10:12:23 +0300 | [diff] [blame] | 139 | |
Roman Elizarov | e1c0b65 | 2017-12-01 14:02:57 +0300 | [diff] [blame] | 140 | def platform = platformOf(it) |
Roman Elizarov | e1a5652 | 2018-04-04 10:31:08 +0300 | [diff] [blame] | 141 | apply from: rootProject.file("gradle/compile-${platform}.gradle") |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 142 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 143 | dependencies { |
| 144 | // See comment below for rationale, it will be replaced with "project" dependency |
| 145 | compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version" |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 146 | |
| 147 | // the only way IDEA can resolve test classes |
| 148 | testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs |
| 149 | } |
| 150 | |
| 151 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all { |
| 152 | kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it } |
| 153 | kotlinOptions.freeCompilerArgs += "-progressive" |
Vsevolod Tolstopyatov | a8904e2 | 2019-07-17 17:22:05 -0700 | [diff] [blame] | 154 | kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses" |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 155 | // Binary compatibility support |
| 156 | kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"] |
| 157 | } |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 158 | } |
| 159 | |
Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 160 | if (build_snapshot_train) { |
| 161 | println "Hacking test tasks, removing stress and flaky tests" |
| 162 | allprojects { |
| 163 | tasks.withType(Test).all { |
Vsevolod Tolstopyatov | dbe3f48 | 2019-04-17 17:51:13 +0300 | [diff] [blame] | 164 | exclude '**/*LinearizabilityTest*' |
| 165 | exclude '**/*LFTest*' |
| 166 | exclude '**/*StressTest*' |
| 167 | exclude '**/*scheduling*' |
| 168 | exclude '**/*Timeout*' |
Vsevolod Tolstopyatov | 1748ce1 | 2019-04-18 14:49:35 +0300 | [diff] [blame] | 169 | exclude '**/*definitely/not/kotlinx*' |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | println "Manifest of kotlin-compiler-embeddable.jar for coroutines" |
| 174 | configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) { |
| 175 | configurations.matching { it.name == "kotlinCompilerClasspath" }.all { |
| 176 | resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each { |
| 177 | def manifest = zipTree(it).matching { |
| 178 | include 'META-INF/MANIFEST.MF' |
| 179 | }.getFiles().first() |
| 180 | |
| 181 | manifest.readLines().each { |
| 182 | println it |
| 183 | } |
| 184 | } |
Vsevolod Tolstopyatov | 585b766 | 2019-04-16 12:10:57 +0300 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 189 | /* |
| 190 | * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies, |
| 191 | * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files |
| 192 | * for JVM-only projects. |
| 193 | * |
| 194 | * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it |
| 195 | * to have out "project" dependency back. |
| 196 | */ |
| 197 | configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) { |
| 198 | configurations.all { |
| 199 | resolutionStrategy.dependencySubstitution { |
| 200 | substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core') |
| 201 | } |
| 202 | } |
| 203 | } |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 204 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 205 | // Redefine source sets because we are not using 'kotlin/main/fqn' folder convention |
| 206 | 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] | 207 | sourceSets { |
Roman Elizarov | f9408f6 | 2018-06-29 20:12:52 +0300 | [diff] [blame] | 208 | main.kotlin.srcDirs = ['src'] |
| 209 | test.kotlin.srcDirs = ['test'] |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 210 | main.resources.srcDirs = ['resources'] |
| 211 | test.resources.srcDirs = ['test-resources'] |
Vsevolod Tolstopyatov | e1fa197 | 2018-06-19 15:54:58 +0300 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 215 | def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/" |
| 216 | 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] | 217 | |
| 218 | configure(subprojects.findAll { !unpublished.contains(it.name) }) { |
Vsevolod Tolstopyatov | fe4e05c | 2019-07-19 12:28:15 +0300 | [diff] [blame] | 219 | if (it.name != 'kotlinx-coroutines-bom') { |
| 220 | apply from: rootProject.file('gradle/dokka.gradle') |
| 221 | } |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 222 | apply from: rootProject.file('gradle/publish-bintray.gradle') |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 223 | } |
| 224 | |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 225 | configure(subprojects.findAll { !unpublished.contains(it.name) }) { |
Vsevolod Tolstopyatov | fe4e05c | 2019-07-19 12:28:15 +0300 | [diff] [blame] | 226 | if (it.name != "kotlinx-coroutines-bom") { |
| 227 | if (it.name != coreModule) { |
| 228 | dokka.dependsOn project(":$coreModule").dokka |
| 229 | tasks.withType(dokka.getClass()) { |
| 230 | externalDocumentationLink { |
| 231 | url = new URL(core_docs_url) |
| 232 | packageListUrl = new URL("file://$core_docs_file") |
| 233 | } |
Roman Elizarov | 65eff0b | 2017-12-20 15:51:31 +0300 | [diff] [blame] | 234 | } |
| 235 | } |
Vsevolod Tolstopyatov | e6e8239 | 2018-10-09 19:06:29 +0300 | [diff] [blame] | 236 | } |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 237 | } |
| 238 | |
Vsevolod Tolstopyatov | e50a0fa | 2019-01-28 11:34:24 +0300 | [diff] [blame] | 239 | // Report Kotlin compiler version when building project |
| 240 | println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION") |
| 241 | |
| 242 | // --------------- Configure sub-projects that are published --------------- |
Roman Elizarov | d2f4b2b | 2019-09-02 17:22:39 +0300 | [diff] [blame] | 243 | task deploy(dependsOn: getTasksByName("publish", true) + getTasksByName("publishNpm", true)) |
Roman Elizarov | 94fb2a3 | 2018-03-05 17:32:59 +0300 | [diff] [blame] | 244 | |
Kirill Timofeev | a518696 | 2017-10-25 14:25:47 +0300 | [diff] [blame] | 245 | apply plugin: 'base' |
| 246 | |
| 247 | clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') } |