blob: 87aac2a1e06852ba611e3d9840bd817f2b2631d9 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
Roman Elizarov660c2d72020-02-14 13:18:37 +03002 * Copyright 2016-2020 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
dkhalanskyjb36512762020-02-21 17:31:05 +030011def sourceless = ['kotlinx.coroutines', 'site', 'kotlinx-coroutines-bom', 'publication-validator']
12def internal = ['kotlinx.coroutines', 'site', 'benchmarks', 'js-stub', 'stdlib-stubs', 'publication-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
Roman Elizarov660c2d72020-02-14 13:18:37 +030044 // Determine if any project dependency is using a snapshot version
45 ext.using_snapshot_version = build_snapshot_train
46 rootProject.properties.each { key, value ->
47 if (key.endsWith("_version") && value instanceof String && value.endsWith("-SNAPSHOT")) {
48 println("NOTE: USING SNAPSHOT VERSION: $key=$value")
49 ext.using_snapshot_version=true
50 }
51 }
52
53 if (using_snapshot_version) {
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030054 repositories {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030055 mavenLocal()
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030056 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
57 }
58 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030059
Kirill Timofeeva5186962017-10-25 14:25:47 +030060 repositories {
61 jcenter()
Roman Elizarov31452902018-04-11 13:58:19 +030062 maven { url "https://kotlin.bintray.com/kotlinx" }
Michael Kuzmin476d6de2019-12-16 22:38:59 +030063 maven {
64 url "https://kotlin.bintray.com/kotlin-dev"
65 credentials {
66 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
67 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
68 }
69 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030070 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov31452902018-04-11 13:58:19 +030071 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030072 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030073 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030074
Kirill Timofeeva5186962017-10-25 14:25:47 +030075 dependencies {
76 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
77 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030078 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov660c2d72020-02-14 13:18:37 +030079 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030080 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Roman Elizarov1ac3dc22020-02-14 15:39:09 +030081 classpath "org.openjfx:javafx-plugin:$javafx_plugin_version"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030082 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030083
84 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030085 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
86 classpath "me.champeau.gradle:jmh-gradle-plugin:0.5.0-rc-2"
87 classpath "net.ltgt.gradle:gradle-apt-plugin:0.21"
Kirill Timofeeva5186962017-10-25 14:25:47 +030088 }
89}
90
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030091import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
92
93// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
94def configureKotlinJvmPlatform(configuration) {
95 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
96}
97
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030098allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030099 // the only place where HostManager could be instantiated
100 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300101 def deployVersion = properties['DeployVersion']
102 if (deployVersion != null) version = deployVersion
103
104 if (build_snapshot_train) {
105 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
106 println "Using Kotlin $kotlin_version for project $it"
107
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +0300108 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
109 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300110 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
111 }
112
113 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300114 }
115
Roman Elizarov660c2d72020-02-14 13:18:37 +0300116 if (using_snapshot_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300117 repositories {
118 mavenLocal()
119 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
120 }
121 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300122
123 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300124
125 // This project property is set during nightly stress test
126 def stressTest = project.properties['stressTest']
127
128 // Copy it to all test tasks
129 tasks.withType(Test) {
130 systemProperty 'stressTest', stressTest
131 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300132}
133
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300134apply plugin: "binary-compatibility-validator"
135apiValidation {
dkhalanskyjb36512762020-02-21 17:31:05 +0300136 ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300137 if (build_snapshot_train) {
138 ignoredProjects.remove("site")
139 ignoredProjects.remove("example-frontend-js")
140 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300141 ignoredPackages += "kotlinx.coroutines.internal"
142}
143
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300144// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300145allprojects {
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300146 String projectName = it.name
Roman Elizarov18fa1162018-06-27 15:13:01 +0300147 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300148 /*
149 * google should be first in the repository list because some of the play services
150 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
151 */
Roman Elizarov660c2d72020-02-14 13:18:37 +0300152 google()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300153 jcenter()
Michael Kuzmin476d6de2019-12-16 22:38:59 +0300154 maven {
155 url "https://kotlin.bintray.com/kotlin-dev"
156 credentials {
157 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
158 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
159 }
160 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +0300161 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov18fa1162018-06-27 15:13:01 +0300162 maven { url "https://kotlin.bintray.com/kotlinx" }
163 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300164}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300165
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300166// Add dependency to core source sets. Core is configured in kx-core/build.gradle
167configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300168 evaluationDependsOn(":$coreModule")
Roman Elizarove1c0b652017-12-01 14:02:57 +0300169 def platform = platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300170 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300171 dependencies {
172 // See comment below for rationale, it will be replaced with "project" dependency
173 compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300174 // the only way IDEA can resolve test classes
175 testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
176 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300177}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300178
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300179// Configure subprojects with Kotlin sources
180configure(subprojects.findAll { !sourceless.contains(it.name) }) {
181 // Use atomicfu plugin, it also adds all the necessary dependencies
182 apply plugin: 'kotlinx-atomicfu'
183
184 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300185 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
186 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
187 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700188 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300189 // Remove null assertions to get smaller bytecode on Android
190 kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300191 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300192}
193
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300194if (build_snapshot_train) {
195 println "Hacking test tasks, removing stress and flaky tests"
196 allprojects {
197 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300198 exclude '**/*LinearizabilityTest*'
199 exclude '**/*LFTest*'
200 exclude '**/*StressTest*'
201 exclude '**/*scheduling*'
202 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300203 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300204 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300205 exclude '**/*CasesPublicAPITest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300206 }
207 }
208
209 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
210 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
211 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
212 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
213 def manifest = zipTree(it).matching {
214 include 'META-INF/MANIFEST.MF'
215 }.getFiles().first()
216
217 manifest.readLines().each {
218 println it
219 }
220 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300221 }
222 }
223}
224
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300225/*
226 * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
227 * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
228 * for JVM-only projects.
229 *
230 * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
231 * to have out "project" dependency back.
232 */
233configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
234 configurations.all {
235 resolutionStrategy.dependencySubstitution {
236 substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
237 }
238 }
239}
Kirill Timofeeva5186962017-10-25 14:25:47 +0300240
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300241// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
242configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300243 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300244 main.kotlin.srcDirs = ['src']
245 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300246 main.resources.srcDirs = ['resources']
247 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300248 }
249}
250
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300251def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
252def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300253
254configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300255 if (it.name != 'kotlinx-coroutines-bom') {
256 apply from: rootProject.file('gradle/dokka.gradle')
257 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300258 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300259}
260
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300261configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300262 if (it.name != "kotlinx-coroutines-bom") {
263 if (it.name != coreModule) {
264 dokka.dependsOn project(":$coreModule").dokka
265 tasks.withType(dokka.getClass()) {
266 externalDocumentationLink {
267 url = new URL(core_docs_url)
Roman Elizarov660c2d72020-02-14 13:18:37 +0300268 packageListUrl = new File(core_docs_file).toURI().toURL()
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300269 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300270 }
271 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300272 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300273}
274
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300275// Report Kotlin compiler version when building project
276println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
277
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300278// --------------- Publish only from under JDK11+ ---------------
279task checkJdkForPublish {
280 doFirst {
281 String javaVersion = System.properties["java.version"]
282 int i = javaVersion.indexOf('.')
283 int javaVersionMajor = (i < 0 ? javaVersion : javaVersion.substring(0, i)).toInteger()
284 if (javaVersionMajor < 11) {
285 throw new GradleException("Project can be build for publishing only under JDK 11+, but found ${javaVersion}")
286 }
287 }
288}
289
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300290// --------------- Configure sub-projects that are published ---------------
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300291def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
292
293publishTasks.each {
294 it.dependsOn checkJdkForPublish
295}
296
297task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300298
Kirill Timofeeva5186962017-10-25 14:25:47 +0300299apply plugin: 'base'
300
301clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300302
303// --------------- Knit configuration ---------------
304
305apply plugin: 'kotlinx-knit'
306
307knit {
308 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
309 moduleRoots = [".", "integration", "reactive", "ui"]
310}
311
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300312knitPrepare.dependsOn getTasksByName("dokka", true)