blob: 08d07782a74288fb8fc48b5a1352b813cb1acaeb [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 Tolstopyatove50a0fa2019-01-28 11:34:24 +03004import org.jetbrains.kotlin.konan.target.HostManager
Sergey Igushkin17248c82020-05-22 12:28:25 +03005import org.gradle.util.VersionNumber
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03006
Victor Turanskye47cb352020-05-12 18:33:04 +03007apply plugin: 'jdk-convention'
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03008apply from: rootProject.file("gradle/experimental.gradle")
9
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030010def coreModule = "kotlinx-coroutines-core"
11// Not applicable for Kotlin plugin
dkhalanskyjb02b403d2020-04-06 16:33:22 +030012def sourceless = ['kotlinx.coroutines', 'site', 'kotlinx-coroutines-bom', 'integration-testing']
13def internal = ['kotlinx.coroutines', 'site', 'benchmarks', 'js-stub', 'stdlib-stubs', 'integration-testing']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030014// Not published
Vsevolod Tolstopyatov5378b802019-09-19 17:39:08 +030015def unpublished = internal + ['example-frontend-js', 'android-unit-tests']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030016
Kirill Timofeeva5186962017-10-25 14:25:47 +030017buildscript {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030018 /*
19 * These property group is used to build kotlinx.coroutines against Kotlin compiler snapshot.
20 * How does it work:
21 * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
22 * atomicfu_version is overwritten by TeamCity environment (AFU is built with snapshot and published to mavenLocal
23 * as previous step or the snapshot build).
24 * Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled.
25 * DO NOT change the name of these properties without adapting kotlinx.train build chain.
26 */
27 def prop = rootProject.properties['build_snapshot_train']
28 ext.build_snapshot_train = prop != null && prop != ""
29 if (build_snapshot_train) {
30 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
31 if (kotlin_version == null) {
32 throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
33 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030034 }
Alexander Likhachev179f1422020-11-18 17:54:33 +030035 // These three flags are enabled in train builds for JVM IR compiler testing
36 ext.jvm_ir_enabled = rootProject.properties['enable_jvm_ir'] != null
37 ext.jvm_ir_api_check_enabled = rootProject.properties['enable_jvm_ir_api_check'] != null
38 ext.native_targets_enabled = rootProject.properties['disable_native_targets'] == null
Roman Elizarove1ac2e52019-04-19 18:51:05 +030039
Roman Elizarov660c2d72020-02-14 13:18:37 +030040 // Determine if any project dependency is using a snapshot version
41 ext.using_snapshot_version = build_snapshot_train
42 rootProject.properties.each { key, value ->
43 if (key.endsWith("_version") && value instanceof String && value.endsWith("-SNAPSHOT")) {
44 println("NOTE: USING SNAPSHOT VERSION: $key=$value")
45 ext.using_snapshot_version=true
46 }
47 }
48
49 if (using_snapshot_version) {
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030050 repositories {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030051 mavenLocal()
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030052 }
53 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030054
Kirill Timofeeva5186962017-10-25 14:25:47 +030055 repositories {
Vsevolod Tolstopyatovad6211c2021-02-10 00:21:58 -080056 maven {url "https://kotlin.bintray.com/kotlinx"}
Vsevolod Tolstopyatov63156a82020-08-24 16:15:52 +030057 // Future replacement for kotlin-dev, with cache redirector
58 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Michael Kuzmin476d6de2019-12-16 22:38:59 +030059 maven {
60 url "https://kotlin.bintray.com/kotlin-dev"
61 credentials {
62 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
63 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
64 }
65 }
Roman Elizarov31452902018-04-11 13:58:19 +030066 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030067 maven { url "https://plugins.gradle.org/m2/" }
Vsevolod Tolstopyatovf2940d52021-03-22 16:11:06 +030068 maven { url "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030069 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030070
Kirill Timofeeva5186962017-10-25 14:25:47 +030071 dependencies {
72 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
73 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030074 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov660c2d72020-02-14 13:18:37 +030075 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030076 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030077 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030078
79 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030080 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
Kirill Timofeeva5186962017-10-25 14:25:47 +030081 }
Roman Elizarov85b1a2b2020-09-14 17:48:17 +030082
83 CacheRedirector.configureBuildScript(buildscript, rootProject)
Kirill Timofeeva5186962017-10-25 14:25:47 +030084}
85
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030086import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
87
Roman Elizarov738f5a22020-10-12 19:03:46 +030088// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
89if (!Idea.active) {
Sergey Igushkin17248c82020-05-22 12:28:25 +030090 ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
91}
92
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030093// 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")
Stanislav Erokhin4b16e1b2020-06-09 09:38:51 +0300140 ignoredProjects.add("kotlinx-coroutines-core")
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300141 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300142 ignoredPackages += "kotlinx.coroutines.internal"
143}
144
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300145// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300146allprojects {
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()
Vsevolod Tolstopyatovad6211c2021-02-10 00:21:58 -0800153 mavenCentral()
Vsevolod Tolstopyatov63156a82020-08-24 16:15:52 +0300154 // Future replacement for kotlin-dev, with cache redirector
155 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Vsevolod Tolstopyatovad6211c2021-02-10 00:21:58 -0800156 maven { url "https://kotlin.bintray.com/kotlinx" }
Roman Elizarov18fa1162018-06-27 15:13:01 +0300157 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300158}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300159
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300160// Add dependency to core source sets. Core is configured in kx-core/build.gradle
161configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300162 evaluationDependsOn(":$coreModule")
Victor Turanskyde388902020-05-02 14:22:30 +0300163 def platform = PlatformKt.platformOf(it)
Vsevolod Tolstopyatov0e926e72021-01-18 08:47:09 -0800164 apply plugin: "kotlin-${platform}-conventions"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300165 dependencies {
166 // See comment below for rationale, it will be replaced with "project" dependency
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100167 api project(":$coreModule")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300168 // the only way IDEA can resolve test classes
Yahor Berdnikaua8d55d62021-03-09 16:38:59 +0100169 testImplementation project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300170 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300171}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300172
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300173// Configure subprojects with Kotlin sources
174configure(subprojects.findAll { !sourceless.contains(it.name) }) {
175 // Use atomicfu plugin, it also adds all the necessary dependencies
176 apply plugin: 'kotlinx-atomicfu'
177
178 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300179 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
180 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
181 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700182 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
Vsevolod Tolstopyatov556f07a2020-12-02 06:52:35 -0800183 // Disable KT-36770 for RxJava2 integration
184 kotlinOptions.freeCompilerArgs += "-XXLanguage:-ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated"
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300185 // Remove null assertions to get smaller bytecode on Android
186 kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300187 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300188}
189
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300190if (build_snapshot_train) {
191 println "Hacking test tasks, removing stress and flaky tests"
192 allprojects {
193 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300194 exclude '**/*LinearizabilityTest*'
195 exclude '**/*LFTest*'
196 exclude '**/*StressTest*'
197 exclude '**/*scheduling*'
198 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300199 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300200 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300201 exclude '**/*CasesPublicAPITest*'
Sergey Igushkin17248c82020-05-22 12:28:25 +0300202 // Kotlin
203 exclude '**/*PrecompiledDebugProbesTest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300204 }
205 }
206
207 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
208 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
209 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
210 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
211 def manifest = zipTree(it).matching {
212 include 'META-INF/MANIFEST.MF'
213 }.getFiles().first()
214
215 manifest.readLines().each {
216 println it
217 }
218 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300219 }
220 }
221}
222
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300223// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
Vsevolod Tolstopyatovfcaa6df2020-08-24 18:57:22 +0300224configure(subprojects.findAll {
225 !sourceless.contains(it.name) &&
226 it.name != "benchmarks" &&
227 it.name != coreModule &&
228 it.name != "example-frontend-js"
229}) {
230 // Pure JS and pure MPP doesn't have this notion and are configured separately
231 // TODO detect it via platformOf and migrate benchmarks to the same scheme
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300232 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300233 main.kotlin.srcDirs = ['src']
234 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300235 main.resources.srcDirs = ['resources']
236 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300237 }
238}
239
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300240def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
241def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300242
243configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300244 if (it.name != 'kotlinx-coroutines-bom') {
245 apply from: rootProject.file('gradle/dokka.gradle')
246 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300247 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300248}
249
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300250configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300251 if (it.name != "kotlinx-coroutines-bom") {
252 if (it.name != coreModule) {
253 dokka.dependsOn project(":$coreModule").dokka
254 tasks.withType(dokka.getClass()) {
255 externalDocumentationLink {
256 url = new URL(core_docs_url)
Roman Elizarov660c2d72020-02-14 13:18:37 +0300257 packageListUrl = new File(core_docs_file).toURI().toURL()
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300258 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300259 }
260 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300261 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300262}
263
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300264// Report Kotlin compiler version when building project
265println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
266
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300267// --------------- Cache redirector ---------------
268
269allprojects {
270 CacheRedirector.configure(project)
271}
272
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300273// --------------- Configure sub-projects that are published ---------------
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300274
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300275def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
276
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300277task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300278
Kirill Timofeeva5186962017-10-25 14:25:47 +0300279apply plugin: 'base'
280
281clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300282
283// --------------- Knit configuration ---------------
284
285apply plugin: 'kotlinx-knit'
286
287knit {
288 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
289 moduleRoots = [".", "integration", "reactive", "ui"]
290}
291
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300292knitPrepare.dependsOn getTasksByName("dokka", true)
Alexander Likhachev179f1422020-11-18 17:54:33 +0300293
294// Disable binary compatibility check for JVM IR compiler output by default
295if (jvm_ir_enabled) {
296 subprojects { project ->
297 configure(tasks.matching { it.name == "apiCheck" }) {
298 enabled = enabled && jvm_ir_api_check_enabled
299 }
300 }
Vsevolod Tolstopyatov556f07a2020-12-02 06:52:35 -0800301}