blob: b54e18b5d1fcf1c68e357a2c5eed22a4ef1e010e [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 Tolstopyatove50a0fa2019-01-28 11:34:24 +030012apply from: rootProject.file("gradle/experimental.gradle")
13
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 // These three flags are enabled in train builds for JVM IR compiler testing
40 ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
41 ext.jvm_ir_api_check_enabled = rootProject.properties['enable_jvm_ir_api_check'] != null
42 ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null
Roman Elizarove1ac2e52019-04-19 18:51:05 +030043
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")
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030049 ext.using_snapshot_version = true
Roman Elizarov660c2d72020-02-14 13:18:37 +030050 }
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 }
57 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030058
Kirill Timofeeva5186962017-10-25 14:25:47 +030059 repositories {
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030060 maven { url "https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev/" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030061 maven { url "https://plugins.gradle.org/m2/" }
Vsevolod Tolstopyatovf2940d52021-03-22 16:11:06 +030062 maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +030063 mavenLocal()
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 Elizarov660c2d72020-02-14 13:18:37 +030070 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030071 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030072 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030073
74 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030075 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
Kirill Timofeeva5186962017-10-25 14:25:47 +030076 }
Roman Elizarov85b1a2b2020-09-14 17:48:17 +030077
78 CacheRedirector.configureBuildScript(buildscript, rootProject)
Kirill Timofeeva5186962017-10-25 14:25:47 +030079}
Roman Elizarov738f5a22020-10-12 19:03:46 +030080// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
81if (!Idea.active) {
Sergey Igushkin17248c82020-05-22 12:28:25 +030082 ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
83}
84
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030085// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
86def configureKotlinJvmPlatform(configuration) {
87 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
88}
89
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030090allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030091 // the only place where HostManager could be instantiated
92 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030093 def deployVersion = properties['DeployVersion']
94 if (deployVersion != null) version = deployVersion
95
96 if (build_snapshot_train) {
97 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
98 println "Using Kotlin $kotlin_version for project $it"
99
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +0300100 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
101 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300102 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
103 }
104
105 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300106 }
107
Roman Elizarov660c2d72020-02-14 13:18:37 +0300108 if (using_snapshot_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300109 repositories {
110 mavenLocal()
111 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
112 }
113 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300114
115 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300116
117 // This project property is set during nightly stress test
118 def stressTest = project.properties['stressTest']
119
120 // Copy it to all test tasks
121 tasks.withType(Test) {
122 systemProperty 'stressTest', stressTest
123 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300124}
125
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300126apply plugin: "binary-compatibility-validator"
127apiValidation {
dkhalanskyjb36512762020-02-21 17:31:05 +0300128 ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300129 if (build_snapshot_train) {
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300130 ignoredProjects.remove("example-frontend-js")
Stanislav Erokhin4b16e1b2020-06-09 09:38:51 +0300131 ignoredProjects.add("kotlinx-coroutines-core")
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300132 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300133 ignoredPackages += "kotlinx.coroutines.internal"
134}
135
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300136// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300137allprojects {
Roman Elizarov18fa1162018-06-27 15:13:01 +0300138 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300139 /*
140 * google should be first in the repository list because some of the play services
141 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
142 */
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300143 mavenLocal()
144 maven { url "https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev/" }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300145 google()
Vsevolod Tolstopyatovad6211c2021-02-10 00:21:58 -0800146 mavenCentral()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300147 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300148}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300149
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300150// Add dependency to core source sets. Core is configured in kx-core/build.gradle
151configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300152 evaluationDependsOn(":$coreModule")
Victor Turanskyde388902020-05-02 14:22:30 +0300153 def platform = PlatformKt.platformOf(it)
Vsevolod Tolstopyatov0e926e72021-01-18 08:47:09 -0800154 apply plugin: "kotlin-${platform}-conventions"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300155 dependencies {
156 // See comment below for rationale, it will be replaced with "project" dependency
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100157 api project(":$coreModule")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300158 // the only way IDEA can resolve test classes
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100159 testImplementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300160 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300161}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300162
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300163// Configure subprojects with Kotlin sources
164configure(subprojects.findAll { !sourceless.contains(it.name) }) {
165 // Use atomicfu plugin, it also adds all the necessary dependencies
166 apply plugin: 'kotlinx-atomicfu'
167
168 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300169 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
170 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
171 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700172 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
Vsevolod Tolstopyatov556f07a2020-12-02 06:52:35 -0800173 // Disable KT-36770 for RxJava2 integration
174 kotlinOptions.freeCompilerArgs += "-XXLanguage:-ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated"
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300175 // Remove null assertions to get smaller bytecode on Android
176 kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300177 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300178}
179
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300180if (build_snapshot_train) {
181 println "Hacking test tasks, removing stress and flaky tests"
182 allprojects {
183 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300184 exclude '**/*LinearizabilityTest*'
185 exclude '**/*LFTest*'
186 exclude '**/*StressTest*'
187 exclude '**/*scheduling*'
188 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300189 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300190 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300191 exclude '**/*CasesPublicAPITest*'
Sergey Igushkin17248c82020-05-22 12:28:25 +0300192 // Kotlin
193 exclude '**/*PrecompiledDebugProbesTest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300194 }
195 }
196
197 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
198 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
199 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
200 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
201 def manifest = zipTree(it).matching {
202 include 'META-INF/MANIFEST.MF'
203 }.getFiles().first()
204
205 manifest.readLines().each {
206 println it
207 }
208 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300209 }
210 }
211}
212
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300213// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
Vsevolod Tolstopyatovfcaa6df2020-08-24 18:57:22 +0300214configure(subprojects.findAll {
215 !sourceless.contains(it.name) &&
216 it.name != "benchmarks" &&
217 it.name != coreModule &&
218 it.name != "example-frontend-js"
219}) {
220 // Pure JS and pure MPP doesn't have this notion and are configured separately
221 // TODO detect it via platformOf and migrate benchmarks to the same scheme
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300222 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300223 main.kotlin.srcDirs = ['src']
224 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300225 main.resources.srcDirs = ['resources']
226 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300227 }
228}
229
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300230def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300231def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/htmlPartial/package-list"
232apply plugin: "org.jetbrains.dokka"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300233
234configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300235 if (it.name != 'kotlinx-coroutines-bom') {
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300236 apply from: rootProject.file('gradle/dokka.gradle.kts')
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300237 }
Vsevolod Tolstopyatov347feed2021-04-22 12:58:39 +0300238 apply from: rootProject.file('gradle/publish.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300239}
240
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300241configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300242 if (it.name != "kotlinx-coroutines-bom") {
243 if (it.name != coreModule) {
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300244 tasks.withType(DokkaTaskPartial.class) {
245 dokkaSourceSets.configureEach {
246 externalDocumentationLink {
247 url.set(new URL(core_docs_url))
248 packageListUrl.set(new File(core_docs_file).toURI().toURL())
249 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300250 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300251 }
252 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300253 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300254}
255
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300256// Report Kotlin compiler version when building project
257println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
258
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300259// --------------- Cache redirector ---------------
260
261allprojects {
262 CacheRedirector.configure(project)
263}
264
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300265// --------------- Configure sub-projects that are published ---------------
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300266
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300267def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
268
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300269task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300270
Kirill Timofeeva5186962017-10-25 14:25:47 +0300271apply plugin: 'base'
272
273clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300274
275// --------------- Knit configuration ---------------
276
277apply plugin: 'kotlinx-knit'
278
279knit {
280 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
281 moduleRoots = [".", "integration", "reactive", "ui"]
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300282 moduleDocs = "build/dokka/htmlPartial"
283 dokkaMultiModuleRoot = "build/dokka/htmlMultiModule/"
Roman Elizarov660c2d72020-02-14 13:18:37 +0300284}
285
Vsevolod Tolstopyatovbcbcd162021-07-06 14:29:27 +0300286knitPrepare.dependsOn getTasksByName("dokkaHtmlMultiModule", true)
287
288dependencies {
289 dokkaHtmlMultiModulePlugin("org.jetbrains.kotlinx:dokka-pathsaver-plugin:$knit_version")
290}
Alexander Likhachev179f1422020-11-18 17:54:33 +0300291
292// Disable binary compatibility check for JVM IR compiler output by default
293if (jvm_ir_enabled) {
294 subprojects { project ->
295 configure(tasks.matching { it.name == "apiCheck" }) {
296 enabled = enabled && jvm_ir_api_check_enabled
297 }
298 }
Vsevolod Tolstopyatov556f07a2020-12-02 06:52:35 -0800299}
Vsevolod Tolstopyatov13926862021-06-07 16:24:21 +0300300
301// Opt-in for build scan in order to troubleshoot Gradle on TC
302if (hasProperty('buildScan')) {
303 buildScan {
304 termsOfServiceUrl = 'https://gradle.com/terms-of-service'
305 termsOfServiceAgree = 'yes'
306 }
307}
308
309/*
310 * kotlinx-coroutines-core dependency leaks into test runtime classpath via kotlin-compiler-embeddable
311 * and conflicts with our own test/runtime incompatibilities (e.g. when class is moved from a main to test),
312 * so we do substitution here
313 */
314allprojects { subProject ->
315 subProject
316 .configurations
317 .matching {
318 // Excluding substituted project itself because of circular dependencies, but still do it
319 // for "*Test*" configurations
320 subProject.name != "kotlinx-coroutines-core" || it.name.contains("Test")
321 }
322 .configureEach { conf ->
323 conf.resolutionStrategy.dependencySubstitution {
324 substitute(module("org.jetbrains.kotlinx:kotlinx-coroutines-core"))
325 .using(project(":kotlinx-coroutines-core"))
326 .because("Because Kotlin compiler embeddable leaks coroutines into the runtime classpath, " +
327 "triggering all sort of incompatible class changes errors")
328 }
329 }
330}