blob: 225634ada33418f7aad168ee8d2c891c8f6403cd [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
7
Victor Turanskye47cb352020-05-12 18:33:04 +03008apply plugin: 'jdk-convention'
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03009apply from: rootProject.file("gradle/experimental.gradle")
10
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030011def coreModule = "kotlinx-coroutines-core"
12// Not applicable for Kotlin plugin
dkhalanskyjb02b403d2020-04-06 16:33:22 +030013def sourceless = ['kotlinx.coroutines', 'site', 'kotlinx-coroutines-bom', 'integration-testing']
14def internal = ['kotlinx.coroutines', 'site', 'benchmarks', 'js-stub', 'stdlib-stubs', 'integration-testing']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030015// Not published
Vsevolod Tolstopyatov5378b802019-09-19 17:39:08 +030016def unpublished = internal + ['example-frontend-js', 'android-unit-tests']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030017
Kirill Timofeeva5186962017-10-25 14:25:47 +030018buildscript {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030019 /*
20 * These property group is used to build kotlinx.coroutines against Kotlin compiler snapshot.
21 * How does it work:
22 * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
23 * atomicfu_version is overwritten by TeamCity environment (AFU is built with snapshot and published to mavenLocal
24 * as previous step or the snapshot build).
25 * Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled.
26 * DO NOT change the name of these properties without adapting kotlinx.train build chain.
27 */
28 def prop = rootProject.properties['build_snapshot_train']
29 ext.build_snapshot_train = prop != null && prop != ""
30 if (build_snapshot_train) {
31 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
32 if (kotlin_version == null) {
33 throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
34 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030035 }
Alexander Likhachev179f1422020-11-18 17:54:33 +030036 // These three flags are enabled in train builds for JVM IR compiler testing
37 ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
38 ext.jvm_ir_api_check_enabled = rootProject.properties['enable_jvm_ir_api_check'] != null
39 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")
46 ext.using_snapshot_version=true
47 }
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 Tolstopyatov347feed2021-04-22 12:58:39 +030057 // Leftover until we migrated to Dokka 1.4.30
58 maven { url "https://kotlin.bintray.com/kotlin-dev" }
Roman Elizarov31452902018-04-11 13:58:19 +030059 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030060 maven { url "https://plugins.gradle.org/m2/" }
Vsevolod Tolstopyatovf2940d52021-03-22 16:11:06 +030061 maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030062 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030063
Kirill Timofeeva5186962017-10-25 14:25:47 +030064 dependencies {
65 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
66 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030067 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov660c2d72020-02-14 13:18:37 +030068 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030069 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030070 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_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"
Kirill Timofeeva5186962017-10-25 14:25:47 +030074 }
Roman Elizarov85b1a2b2020-09-14 17:48:17 +030075
76 CacheRedirector.configureBuildScript(buildscript, rootProject)
Kirill Timofeeva5186962017-10-25 14:25:47 +030077}
Roman Elizarov738f5a22020-10-12 19:03:46 +030078// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
79if (!Idea.active) {
Sergey Igushkin17248c82020-05-22 12:28:25 +030080 ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
81}
82
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030083// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
84def configureKotlinJvmPlatform(configuration) {
85 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
86}
87
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030088allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030089 // the only place where HostManager could be instantiated
90 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030091 def deployVersion = properties['DeployVersion']
92 if (deployVersion != null) version = deployVersion
93
94 if (build_snapshot_train) {
95 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
96 println "Using Kotlin $kotlin_version for project $it"
97
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +030098 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
99 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300100 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
101 }
102
103 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300104 }
105
Roman Elizarov660c2d72020-02-14 13:18:37 +0300106 if (using_snapshot_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300107 repositories {
108 mavenLocal()
109 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
110 }
111 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300112
113 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300114
115 // This project property is set during nightly stress test
116 def stressTest = project.properties['stressTest']
117
118 // Copy it to all test tasks
119 tasks.withType(Test) {
120 systemProperty 'stressTest', stressTest
121 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300122}
123
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300124apply plugin: "binary-compatibility-validator"
125apiValidation {
dkhalanskyjb36512762020-02-21 17:31:05 +0300126 ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300127 if (build_snapshot_train) {
128 ignoredProjects.remove("site")
129 ignoredProjects.remove("example-frontend-js")
Stanislav Erokhin4b16e1b2020-06-09 09:38:51 +0300130 ignoredProjects.add("kotlinx-coroutines-core")
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300131 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300132 ignoredPackages += "kotlinx.coroutines.internal"
133}
134
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300135// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300136allprojects {
Roman Elizarov18fa1162018-06-27 15:13:01 +0300137 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300138 /*
139 * google should be first in the repository list because some of the play services
140 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
141 */
Roman Elizarov660c2d72020-02-14 13:18:37 +0300142 google()
Vsevolod Tolstopyatovad6211c2021-02-10 00:21:58 -0800143 mavenCentral()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300144 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300145}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300146
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300147// Add dependency to core source sets. Core is configured in kx-core/build.gradle
148configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300149 evaluationDependsOn(":$coreModule")
Victor Turanskyde388902020-05-02 14:22:30 +0300150 def platform = PlatformKt.platformOf(it)
Vsevolod Tolstopyatov0e926e72021-01-18 08:47:09 -0800151 apply plugin: "kotlin-${platform}-conventions"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300152 dependencies {
153 // See comment below for rationale, it will be replaced with "project" dependency
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100154 api project(":$coreModule")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300155 // the only way IDEA can resolve test classes
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100156 testImplementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300157 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300158}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300159
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300160// Configure subprojects with Kotlin sources
161configure(subprojects.findAll { !sourceless.contains(it.name) }) {
162 // Use atomicfu plugin, it also adds all the necessary dependencies
163 apply plugin: 'kotlinx-atomicfu'
164
165 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300166 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
167 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
168 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700169 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
Vsevolod Tolstopyatov556f07a2020-12-02 06:52:35 -0800170 // Disable KT-36770 for RxJava2 integration
171 kotlinOptions.freeCompilerArgs += "-XXLanguage:-ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated"
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300172 // Remove null assertions to get smaller bytecode on Android
173 kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300174 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300175}
176
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300177if (build_snapshot_train) {
178 println "Hacking test tasks, removing stress and flaky tests"
179 allprojects {
180 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300181 exclude '**/*LinearizabilityTest*'
182 exclude '**/*LFTest*'
183 exclude '**/*StressTest*'
184 exclude '**/*scheduling*'
185 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300186 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300187 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300188 exclude '**/*CasesPublicAPITest*'
Sergey Igushkin17248c82020-05-22 12:28:25 +0300189 // Kotlin
190 exclude '**/*PrecompiledDebugProbesTest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300191 }
192 }
193
194 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
195 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
196 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
197 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
198 def manifest = zipTree(it).matching {
199 include 'META-INF/MANIFEST.MF'
200 }.getFiles().first()
201
202 manifest.readLines().each {
203 println it
204 }
205 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300206 }
207 }
208}
209
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300210// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
Vsevolod Tolstopyatovfcaa6df2020-08-24 18:57:22 +0300211configure(subprojects.findAll {
212 !sourceless.contains(it.name) &&
213 it.name != "benchmarks" &&
214 it.name != coreModule &&
215 it.name != "example-frontend-js"
216}) {
217 // Pure JS and pure MPP doesn't have this notion and are configured separately
218 // TODO detect it via platformOf and migrate benchmarks to the same scheme
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300219 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300220 main.kotlin.srcDirs = ['src']
221 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300222 main.resources.srcDirs = ['resources']
223 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300224 }
225}
226
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300227def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
228def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300229
230configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300231 if (it.name != 'kotlinx-coroutines-bom') {
232 apply from: rootProject.file('gradle/dokka.gradle')
233 }
Vsevolod Tolstopyatov347feed2021-04-22 12:58:39 +0300234 apply from: rootProject.file('gradle/publish.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300235}
236
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300237configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300238 if (it.name != "kotlinx-coroutines-bom") {
239 if (it.name != coreModule) {
240 dokka.dependsOn project(":$coreModule").dokka
241 tasks.withType(dokka.getClass()) {
242 externalDocumentationLink {
243 url = new URL(core_docs_url)
Roman Elizarov660c2d72020-02-14 13:18:37 +0300244 packageListUrl = new File(core_docs_file).toURI().toURL()
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300245 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300246 }
247 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300248 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300249}
250
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300251// Report Kotlin compiler version when building project
252println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
253
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300254// --------------- Cache redirector ---------------
255
256allprojects {
257 CacheRedirector.configure(project)
258}
259
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300260// --------------- Configure sub-projects that are published ---------------
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300261
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300262def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
263
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300264task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300265
Kirill Timofeeva5186962017-10-25 14:25:47 +0300266apply plugin: 'base'
267
268clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300269
270// --------------- Knit configuration ---------------
271
272apply plugin: 'kotlinx-knit'
273
274knit {
275 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
276 moduleRoots = [".", "integration", "reactive", "ui"]
277}
278
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300279knitPrepare.dependsOn getTasksByName("dokka", true)
Alexander Likhachev179f1422020-11-18 17:54:33 +0300280
281// Disable binary compatibility check for JVM IR compiler output by default
282if (jvm_ir_enabled) {
283 subprojects { project ->
284 configure(tasks.matching { it.name == "apiCheck" }) {
285 enabled = enabled && jvm_ir_api_check_enabled
286 }
287 }
Vsevolod Tolstopyatov556f07a2020-12-02 06:52:35 -0800288}
Vsevolod Tolstopyatov13926862021-06-07 16:24:21 +0300289
290// Opt-in for build scan in order to troubleshoot Gradle on TC
291if (hasProperty('buildScan')) {
292 buildScan {
293 termsOfServiceUrl = 'https://gradle.com/terms-of-service'
294 termsOfServiceAgree = 'yes'
295 }
296}
297
298/*
299 * kotlinx-coroutines-core dependency leaks into test runtime classpath via kotlin-compiler-embeddable
300 * and conflicts with our own test/runtime incompatibilities (e.g. when class is moved from a main to test),
301 * so we do substitution here
302 */
303allprojects { subProject ->
304 subProject
305 .configurations
306 .matching {
307 // Excluding substituted project itself because of circular dependencies, but still do it
308 // for "*Test*" configurations
309 subProject.name != "kotlinx-coroutines-core" || it.name.contains("Test")
310 }
311 .configureEach { conf ->
312 conf.resolutionStrategy.dependencySubstitution {
313 substitute(module("org.jetbrains.kotlinx:kotlinx-coroutines-core"))
314 .using(project(":kotlinx-coroutines-core"))
315 .because("Because Kotlin compiler embeddable leaks coroutines into the runtime classpath, " +
316 "triggering all sort of incompatible class changes errors")
317 }
318 }
319}