blob: 94db6c08c8068837325bd16a2dfde8b79dedeb26 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03002 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03003 */
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03004import org.jetbrains.kotlin.konan.target.HostManager
5
6apply from: rootProject.file("gradle/experimental.gradle")
7
8def rootModule = "kotlinx.coroutines"
9def coreModule = "kotlinx-coroutines-core"
10// Not applicable for Kotlin plugin
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +030011def sourceless = ['kotlinx.coroutines', 'site', 'kotlinx-coroutines-bom']
12def internal = ['kotlinx.coroutines', 'site', 'benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030013// Not published
Vsevolod Tolstopyatov5378b802019-09-19 17:39:08 +030014def unpublished = internal + ['example-frontend-js', 'android-unit-tests']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030015
16static 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 Elizarov1f74a2d2018-06-29 19:19:45 +030024
Kirill Timofeeva5186962017-10-25 14:25:47 +030025buildscript {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030026 /*
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 Elizarove1ac2e52019-04-19 18:51:05 +030042 }
43
44 if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT")) {
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030045 repositories {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030046 mavenLocal()
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030047 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
48 }
49 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030050
Kirill Timofeeva5186962017-10-25 14:25:47 +030051 repositories {
52 jcenter()
Roman Elizarov31452902018-04-11 13:58:19 +030053 maven { url "https://kotlin.bintray.com/kotlinx" }
Michael Kuzmin476d6de2019-12-16 22:38:59 +030054 maven {
55 url "https://kotlin.bintray.com/kotlin-dev"
56 credentials {
57 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
58 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
59 }
60 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030061 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov31452902018-04-11 13:58:19 +030062 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030063 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030064 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030065
Kirill Timofeeva5186962017-10-25 14:25:47 +030066 dependencies {
67 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
68 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030069 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030070 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030071
72 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030073 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
74 classpath "me.champeau.gradle:jmh-gradle-plugin:0.5.0-rc-2"
75 classpath "net.ltgt.gradle:gradle-apt-plugin:0.21"
Kirill Timofeeva5186962017-10-25 14:25:47 +030076 }
77}
78
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030079import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
80
81// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
82def configureKotlinJvmPlatform(configuration) {
83 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
84}
85
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030086allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030087 // the only place where HostManager could be instantiated
88 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030089 def deployVersion = properties['DeployVersion']
90 if (deployVersion != null) version = deployVersion
91
92 if (build_snapshot_train) {
93 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
94 println "Using Kotlin $kotlin_version for project $it"
95
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +030096 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
97 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030098 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
99 }
100
101 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300102 }
103
Nikita Koval4f24a7a2019-11-12 15:54:50 +0300104 if (build_snapshot_train || atomicfu_version.endsWith("-SNAPSHOT") || lincheck_version.endsWith("-SNAPSHOT")) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300105 repositories {
106 mavenLocal()
107 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
108 }
109 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300110
111 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300112
113 // This project property is set during nightly stress test
114 def stressTest = project.properties['stressTest']
115
116 // Copy it to all test tasks
117 tasks.withType(Test) {
118 systemProperty 'stressTest', stressTest
119 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300120}
121
122allprojects {
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300123 apply plugin: 'kotlinx-atomicfu' // it also adds all the necessary dependencies
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300124 def projectName = it.name
Roman Elizarov18fa1162018-06-27 15:13:01 +0300125 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300126 /*
127 * google should be first in the repository list because some of the play services
128 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
129 */
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300130 if (projectName == "kotlinx-coroutines-play-services") {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300131 google()
132 }
Roman Elizarov18fa1162018-06-27 15:13:01 +0300133 jcenter()
Michael Kuzmin476d6de2019-12-16 22:38:59 +0300134 maven {
135 url "https://kotlin.bintray.com/kotlin-dev"
136 credentials {
137 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
138 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
139 }
140 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +0300141 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov18fa1162018-06-27 15:13:01 +0300142 maven { url "https://kotlin.bintray.com/kotlinx" }
143 }
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300144
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300145 if (projectName == rootModule || projectName == coreModule) return
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300146
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300147 // Add dependency to core source sets. Core is configured in kx-core/build.gradle
148 evaluationDependsOn(":$coreModule")
149 if (sourceless.contains(projectName)) return
Roman Elizarov38b6fd32018-01-17 10:12:23 +0300150
Roman Elizarove1c0b652017-12-01 14:02:57 +0300151 def platform = platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300152 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300153
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300154 dependencies {
155 // See comment below for rationale, it will be replaced with "project" dependency
156 compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300157
158 // the only way IDEA can resolve test classes
159 testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
160 }
161
162 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
163 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
164 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700165 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300166 // Binary compatibility support
167 kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
168 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300169}
170
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300171if (build_snapshot_train) {
172 println "Hacking test tasks, removing stress and flaky tests"
173 allprojects {
174 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300175 exclude '**/*LinearizabilityTest*'
176 exclude '**/*LFTest*'
177 exclude '**/*StressTest*'
178 exclude '**/*scheduling*'
179 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300180 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300181 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300182 exclude '**/*CasesPublicAPITest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300183 }
184 }
185
186 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
187 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
188 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
189 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
190 def manifest = zipTree(it).matching {
191 include 'META-INF/MANIFEST.MF'
192 }.getFiles().first()
193
194 manifest.readLines().each {
195 println it
196 }
197 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300198 }
199 }
200}
201
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300202/*
203 * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
204 * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
205 * for JVM-only projects.
206 *
207 * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
208 * to have out "project" dependency back.
209 */
210configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
211 configurations.all {
212 resolutionStrategy.dependencySubstitution {
213 substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
214 }
215 }
216}
Kirill Timofeeva5186962017-10-25 14:25:47 +0300217
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300218// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
219configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300220 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300221 main.kotlin.srcDirs = ['src']
222 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300223 main.resources.srcDirs = ['resources']
224 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300225 }
226}
227
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300228def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
229def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300230
231configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300232 if (it.name != 'kotlinx-coroutines-bom') {
233 apply from: rootProject.file('gradle/dokka.gradle')
234 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300235 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300236}
237
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300238configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300239 if (it.name != "kotlinx-coroutines-bom") {
240 if (it.name != coreModule) {
241 dokka.dependsOn project(":$coreModule").dokka
242 tasks.withType(dokka.getClass()) {
243 externalDocumentationLink {
244 url = new URL(core_docs_url)
245 packageListUrl = new URL("file://$core_docs_file")
246 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300247 }
248 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300249 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300250}
251
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300252// Report Kotlin compiler version when building project
253println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
254
255// --------------- Configure sub-projects that are published ---------------
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +0300256task deploy(dependsOn: getTasksByName("publish", true) + getTasksByName("publishNpm", true))
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300257
Kirill Timofeeva5186962017-10-25 14:25:47 +0300258apply plugin: 'base'
259
260clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }