blob: e4b12ff3adfc6a7ff6f9d321e7fa9c0a6024b2e8 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
Vsevolod Tolstopyatov0e926e72021-01-18 08:47:09 -08002 * Copyright 2016-2021 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 Tolstopyatov13926862021-06-07 16:24:21 +03004
5import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03006import org.jetbrains.kotlin.konan.target.HostManager
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +03007import org.gradle.util.VersionNumber
8import org.jetbrains.dokka.gradle.DokkaTaskPartial
9import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030010
Victor Turanskye47cb352020-05-12 18:33:04 +030011apply plugin: 'jdk-convention'
Vsevolod Tolstopyatovf5e87402021-07-08 13:47:21 +030012apply from: rootProject.file("gradle/opt-in.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030013
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030014def coreModule = "kotlinx-coroutines-core"
15// Not applicable for Kotlin plugin
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030016def sourceless = ['kotlinx.coroutines', 'kotlinx-coroutines-bom', 'integration-testing']
17def internal = ['kotlinx.coroutines', 'benchmarks', 'integration-testing']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030018// Not published
Vsevolod Tolstopyatov5378b802019-09-19 17:39:08 +030019def unpublished = internal + ['example-frontend-js', 'android-unit-tests']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030020
Kirill Timofeeva5186962017-10-25 14:25:47 +030021buildscript {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030022 /*
23 * These property group is used to build kotlinx.coroutines against Kotlin compiler snapshot.
24 * How does it work:
25 * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
26 * atomicfu_version is overwritten by TeamCity environment (AFU is built with snapshot and published to mavenLocal
27 * as previous step or the snapshot build).
28 * Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled.
29 * DO NOT change the name of these properties without adapting kotlinx.train build chain.
30 */
31 def prop = rootProject.properties['build_snapshot_train']
32 ext.build_snapshot_train = prop != null && prop != ""
33 if (build_snapshot_train) {
34 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
35 if (kotlin_version == null) {
36 throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
37 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030038 }
Alexander Likhachev179f1422020-11-18 17:54:33 +030039 ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null
Roman Elizarove1ac2e52019-04-19 18:51:05 +030040
Roman Elizarov660c2d72020-02-14 13:18:37 +030041 // Determine if any project dependency is using a snapshot version
42 ext.using_snapshot_version = build_snapshot_train
43 rootProject.properties.each { key, value ->
44 if (key.endsWith("_version") && value instanceof String && value.endsWith("-SNAPSHOT")) {
45 println("NOTE: USING SNAPSHOT VERSION: $key=$value")
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030046 ext.using_snapshot_version = true
Roman Elizarov660c2d72020-02-14 13:18:37 +030047 }
48 }
49
50 if (using_snapshot_version) {
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030051 repositories {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030052 mavenLocal()
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030053 }
54 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030055
Kirill Timofeeva5186962017-10-25 14:25:47 +030056 repositories {
Vsevolod Tolstopyatov69c3ce32021-07-08 18:47:54 +030057 mavenCentral()
Roman Elizarov65eff0b2017-12-20 15:51:31 +030058 maven { url "https://plugins.gradle.org/m2/" }
Vsevolod Tolstopyatovf2940d52021-03-22 16:11:06 +030059 maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030060 mavenLocal()
Kirill Timofeeva5186962017-10-25 14:25:47 +030061 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030062
Kirill Timofeeva5186962017-10-25 14:25:47 +030063 dependencies {
64 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
65 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030066 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov660c2d72020-02-14 13:18:37 +030067 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030068 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030069 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030070
71 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030072 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
Kirill Timofeeva5186962017-10-25 14:25:47 +030073 }
Roman Elizarov85b1a2b2020-09-14 17:48:17 +030074
75 CacheRedirector.configureBuildScript(buildscript, rootProject)
Kirill Timofeeva5186962017-10-25 14:25:47 +030076}
Roman Elizarov738f5a22020-10-12 19:03:46 +030077// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
78if (!Idea.active) {
Sergey Igushkin17248c82020-05-22 12:28:25 +030079 ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
80}
81
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030082// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
83def configureKotlinJvmPlatform(configuration) {
84 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
85}
86
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030087allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030088 // the only place where HostManager could be instantiated
89 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030090 def deployVersion = properties['DeployVersion']
91 if (deployVersion != null) version = deployVersion
92
93 if (build_snapshot_train) {
94 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
95 println "Using Kotlin $kotlin_version for project $it"
96
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +030097 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
98 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030099 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
100 }
101
102 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300103 }
104
Roman Elizarov660c2d72020-02-14 13:18:37 +0300105 if (using_snapshot_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300106 repositories {
107 mavenLocal()
108 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
109 }
110 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300111
112 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300113
114 // This project property is set during nightly stress test
115 def stressTest = project.properties['stressTest']
116
117 // Copy it to all test tasks
118 tasks.withType(Test) {
119 systemProperty 'stressTest', stressTest
120 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300121}
122
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300123apply plugin: "binary-compatibility-validator"
124apiValidation {
dkhalanskyjb36512762020-02-21 17:31:05 +0300125 ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300126 if (build_snapshot_train) {
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300127 ignoredProjects.remove("example-frontend-js")
Stanislav Erokhin4b16e1b2020-06-09 09:38:51 +0300128 ignoredProjects.add("kotlinx-coroutines-core")
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300129 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300130 ignoredPackages += "kotlinx.coroutines.internal"
131}
132
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300133// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300134allprojects {
Roman Elizarov18fa1162018-06-27 15:13:01 +0300135 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300136 /*
137 * google should be first in the repository list because some of the play services
138 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
139 */
Roman Elizarov660c2d72020-02-14 13:18:37 +0300140 google()
Vsevolod Tolstopyatovad6211c2021-02-10 00:21:58 -0800141 mavenCentral()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300142 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300143}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300144
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300145// Add dependency to core source sets. Core is configured in kx-core/build.gradle
146configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300147 evaluationDependsOn(":$coreModule")
Victor Turanskyde388902020-05-02 14:22:30 +0300148 def platform = PlatformKt.platformOf(it)
Vsevolod Tolstopyatov0e926e72021-01-18 08:47:09 -0800149 apply plugin: "kotlin-${platform}-conventions"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300150 dependencies {
151 // See comment below for rationale, it will be replaced with "project" dependency
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100152 api project(":$coreModule")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300153 // the only way IDEA can resolve test classes
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100154 testImplementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300155 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300156}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300157
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300158// Configure subprojects with Kotlin sources
159configure(subprojects.findAll { !sourceless.contains(it.name) }) {
160 // Use atomicfu plugin, it also adds all the necessary dependencies
161 apply plugin: 'kotlinx-atomicfu'
162
163 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300164 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
Vsevolod Tolstopyatovf5e87402021-07-08 13:47:21 +0300165 kotlinOptions.freeCompilerArgs += optInAnnotations.collect { "-Xopt-in=" + it }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300166 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatov556f07a2020-12-02 06:52:35 -0800167 // Disable KT-36770 for RxJava2 integration
168 kotlinOptions.freeCompilerArgs += "-XXLanguage:-ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated"
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300169 // Remove null assertions to get smaller bytecode on Android
170 kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300171 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300172}
173
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300174if (build_snapshot_train) {
175 println "Hacking test tasks, removing stress and flaky tests"
176 allprojects {
177 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300178 exclude '**/*LinearizabilityTest*'
179 exclude '**/*LFTest*'
180 exclude '**/*StressTest*'
181 exclude '**/*scheduling*'
182 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300183 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300184 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300185 exclude '**/*CasesPublicAPITest*'
Sergey Igushkin17248c82020-05-22 12:28:25 +0300186 // Kotlin
187 exclude '**/*PrecompiledDebugProbesTest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300188 }
189 }
190
191 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
192 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
193 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
194 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
195 def manifest = zipTree(it).matching {
196 include 'META-INF/MANIFEST.MF'
197 }.getFiles().first()
198
199 manifest.readLines().each {
200 println it
201 }
202 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300203 }
204 }
205}
206
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300207// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
Vsevolod Tolstopyatovfcaa6df2020-08-24 18:57:22 +0300208configure(subprojects.findAll {
209 !sourceless.contains(it.name) &&
210 it.name != "benchmarks" &&
211 it.name != coreModule &&
212 it.name != "example-frontend-js"
213}) {
214 // Pure JS and pure MPP doesn't have this notion and are configured separately
215 // TODO detect it via platformOf and migrate benchmarks to the same scheme
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300216 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300217 main.kotlin.srcDirs = ['src']
218 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300219 main.resources.srcDirs = ['resources']
220 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300221 }
222}
223
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300224def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300225def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/htmlPartial/package-list"
226apply plugin: "org.jetbrains.dokka"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300227
228configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300229 if (it.name != 'kotlinx-coroutines-bom') {
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300230 apply from: rootProject.file('gradle/dokka.gradle.kts')
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300231 }
Vsevolod Tolstopyatov347feed2021-04-22 12:58:39 +0300232 apply from: rootProject.file('gradle/publish.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300233}
234
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300235configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300236 if (it.name != "kotlinx-coroutines-bom") {
237 if (it.name != coreModule) {
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300238 tasks.withType(DokkaTaskPartial.class) {
239 dokkaSourceSets.configureEach {
240 externalDocumentationLink {
241 url.set(new URL(core_docs_url))
242 packageListUrl.set(new File(core_docs_file).toURI().toURL())
243 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300244 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300245 }
246 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300247 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300248}
249
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300250// Report Kotlin compiler version when building project
251println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
252
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300253// --------------- Cache redirector ---------------
254
255allprojects {
256 CacheRedirector.configure(project)
257}
258
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300259// --------------- Configure sub-projects that are published ---------------
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300260
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300261def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
262
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300263task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300264
Kirill Timofeeva5186962017-10-25 14:25:47 +0300265apply plugin: 'base'
266
267clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300268
269// --------------- Knit configuration ---------------
270
271apply plugin: 'kotlinx-knit'
272
273knit {
274 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
275 moduleRoots = [".", "integration", "reactive", "ui"]
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300276 moduleDocs = "build/dokka/htmlPartial"
277 dokkaMultiModuleRoot = "build/dokka/htmlMultiModule/"
Roman Elizarov660c2d72020-02-14 13:18:37 +0300278}
279
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300280knitPrepare.dependsOn getTasksByName("dokkaHtmlMultiModule", true)
281
282dependencies {
283 dokkaHtmlMultiModulePlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
284}
Alexander Likhachev179f1422020-11-18 17:54:33 +0300285
Vsevolod Tolstopyatov13926862021-06-07 16:24:21 +0300286// Opt-in for build scan in order to troubleshoot Gradle on TC
287if (hasProperty('buildScan')) {
288 buildScan {
289 termsOfServiceUrl = 'https://gradle.com/terms-of-service'
290 termsOfServiceAgree = 'yes'
291 }
292}
293
294/*
295 * kotlinx-coroutines-core dependency leaks into test runtime classpath via kotlin-compiler-embeddable
296 * and conflicts with our own test/runtime incompatibilities (e.g. when class is moved from a main to test),
297 * so we do substitution here
298 */
299allprojects { subProject ->
300 subProject
301 .configurations
302 .matching {
303 // Excluding substituted project itself because of circular dependencies, but still do it
304 // for "*Test*" configurations
305 subProject.name != "kotlinx-coroutines-core" || it.name.contains("Test")
306 }
307 .configureEach { conf ->
308 conf.resolutionStrategy.dependencySubstitution {
309 substitute(module("org.jetbrains.kotlinx:kotlinx-coroutines-core"))
310 .using(project(":kotlinx-coroutines-core"))
311 .because("Because Kotlin compiler embeddable leaks coroutines into the runtime classpath, " +
312 "triggering all sort of incompatible class changes errors")
313 }
314 }
315}