blob: 79c7f3553e99b7d559f2db90c7a08a7dfd5717e4 [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
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
10def rootModule = "kotlinx.coroutines"
11def 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 }
36
Roman Elizarov660c2d72020-02-14 13:18:37 +030037 // Determine if any project dependency is using a snapshot version
38 ext.using_snapshot_version = build_snapshot_train
39 rootProject.properties.each { key, value ->
40 if (key.endsWith("_version") && value instanceof String && value.endsWith("-SNAPSHOT")) {
41 println("NOTE: USING SNAPSHOT VERSION: $key=$value")
42 ext.using_snapshot_version=true
43 }
44 }
45
46 if (using_snapshot_version) {
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030047 repositories {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030048 mavenLocal()
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030049 }
50 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030051
Kirill Timofeeva5186962017-10-25 14:25:47 +030052 repositories {
53 jcenter()
Vsevolod Tolstopyatov2d0d9aa2020-08-13 15:34:49 +030054 maven {
55 url "https://kotlin.bintray.com/kotlinx"
56 credentials {
57 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
58 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
59 }
60 }
Vsevolod Tolstopyatov63156a82020-08-24 16:15:52 +030061 // Future replacement for kotlin-dev, with cache redirector
62 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
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"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030081 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030082
83 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030084 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
Kirill Timofeeva5186962017-10-25 14:25:47 +030085 }
Roman Elizarov85b1a2b2020-09-14 17:48:17 +030086
87 CacheRedirector.configureBuildScript(buildscript, rootProject)
Kirill Timofeeva5186962017-10-25 14:25:47 +030088}
89
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030090import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
91
Roman Elizarov738f5a22020-10-12 19:03:46 +030092// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
93if (!Idea.active) {
Sergey Igushkin17248c82020-05-22 12:28:25 +030094 ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
95}
96
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030097// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
98def configureKotlinJvmPlatform(configuration) {
99 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
100}
101
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300102allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300103 // the only place where HostManager could be instantiated
104 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300105 def deployVersion = properties['DeployVersion']
106 if (deployVersion != null) version = deployVersion
107
108 if (build_snapshot_train) {
109 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
110 println "Using Kotlin $kotlin_version for project $it"
111
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +0300112 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
113 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300114 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
115 }
116
117 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300118 }
119
Roman Elizarov660c2d72020-02-14 13:18:37 +0300120 if (using_snapshot_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300121 repositories {
122 mavenLocal()
123 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
124 }
125 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300126
127 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300128
129 // This project property is set during nightly stress test
130 def stressTest = project.properties['stressTest']
131
132 // Copy it to all test tasks
133 tasks.withType(Test) {
134 systemProperty 'stressTest', stressTest
135 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300136}
137
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300138apply plugin: "binary-compatibility-validator"
139apiValidation {
dkhalanskyjb36512762020-02-21 17:31:05 +0300140 ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300141 if (build_snapshot_train) {
142 ignoredProjects.remove("site")
143 ignoredProjects.remove("example-frontend-js")
Stanislav Erokhin4b16e1b2020-06-09 09:38:51 +0300144 ignoredProjects.add("kotlinx-coroutines-core")
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300145 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300146 ignoredPackages += "kotlinx.coroutines.internal"
147}
148
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300149// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300150allprojects {
Roman Elizarov18fa1162018-06-27 15:13:01 +0300151 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300152 /*
153 * google should be first in the repository list because some of the play services
154 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
155 */
Roman Elizarov660c2d72020-02-14 13:18:37 +0300156 google()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300157 jcenter()
Vsevolod Tolstopyatov63156a82020-08-24 16:15:52 +0300158 // Future replacement for kotlin-dev, with cache redirector
159 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Michael Kuzmin476d6de2019-12-16 22:38:59 +0300160 maven {
161 url "https://kotlin.bintray.com/kotlin-dev"
162 credentials {
163 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
164 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
165 }
166 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +0300167 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Vsevolod Tolstopyatov2d0d9aa2020-08-13 15:34:49 +0300168 maven {
169 url "https://kotlin.bintray.com/kotlinx"
170 credentials {
171 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
172 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
173 }
174 }
175 mavenLocal()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300176 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300177}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300178
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300179// Add dependency to core source sets. Core is configured in kx-core/build.gradle
180configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300181 evaluationDependsOn(":$coreModule")
Victor Turanskyde388902020-05-02 14:22:30 +0300182 def platform = PlatformKt.platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300183 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300184 dependencies {
185 // See comment below for rationale, it will be replaced with "project" dependency
186 compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300187 // the only way IDEA can resolve test classes
188 testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
189 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300190}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300191
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300192// Configure subprojects with Kotlin sources
193configure(subprojects.findAll { !sourceless.contains(it.name) }) {
194 // Use atomicfu plugin, it also adds all the necessary dependencies
195 apply plugin: 'kotlinx-atomicfu'
196
197 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300198 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
199 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
200 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700201 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300202 // Remove null assertions to get smaller bytecode on Android
203 kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300204 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300205}
206
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300207if (build_snapshot_train) {
208 println "Hacking test tasks, removing stress and flaky tests"
209 allprojects {
210 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300211 exclude '**/*LinearizabilityTest*'
212 exclude '**/*LFTest*'
213 exclude '**/*StressTest*'
214 exclude '**/*scheduling*'
215 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300216 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300217 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300218 exclude '**/*CasesPublicAPITest*'
Sergey Igushkin17248c82020-05-22 12:28:25 +0300219 // Kotlin
220 exclude '**/*PrecompiledDebugProbesTest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300221 }
222 }
223
224 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
225 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
226 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
227 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
228 def manifest = zipTree(it).matching {
229 include 'META-INF/MANIFEST.MF'
230 }.getFiles().first()
231
232 manifest.readLines().each {
233 println it
234 }
235 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300236 }
237 }
238}
239
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300240/*
241 * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
242 * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
243 * for JVM-only projects.
244 *
Victor Turanskya8f4b642020-04-28 14:30:02 +0300245 * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300246 * to have out "project" dependency back.
247 */
248configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
249 configurations.all {
250 resolutionStrategy.dependencySubstitution {
251 substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
252 }
253 }
254}
Kirill Timofeeva5186962017-10-25 14:25:47 +0300255
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300256// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
Vsevolod Tolstopyatovfcaa6df2020-08-24 18:57:22 +0300257configure(subprojects.findAll {
258 !sourceless.contains(it.name) &&
259 it.name != "benchmarks" &&
260 it.name != coreModule &&
261 it.name != "example-frontend-js"
262}) {
263 // Pure JS and pure MPP doesn't have this notion and are configured separately
264 // TODO detect it via platformOf and migrate benchmarks to the same scheme
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300265 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300266 main.kotlin.srcDirs = ['src']
267 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300268 main.resources.srcDirs = ['resources']
269 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300270 }
271}
272
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300273def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
274def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300275
276configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300277 if (it.name != 'kotlinx-coroutines-bom') {
278 apply from: rootProject.file('gradle/dokka.gradle')
279 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300280 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300281}
282
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300283configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300284 if (it.name != "kotlinx-coroutines-bom") {
285 if (it.name != coreModule) {
286 dokka.dependsOn project(":$coreModule").dokka
287 tasks.withType(dokka.getClass()) {
288 externalDocumentationLink {
289 url = new URL(core_docs_url)
Roman Elizarov660c2d72020-02-14 13:18:37 +0300290 packageListUrl = new File(core_docs_file).toURI().toURL()
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300291 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300292 }
293 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300294 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300295}
296
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300297// Report Kotlin compiler version when building project
298println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
299
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300300// --------------- Cache redirector ---------------
301
302allprojects {
303 CacheRedirector.configure(project)
304}
305
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300306// --------------- Configure sub-projects that are published ---------------
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300307
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300308def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
309
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300310task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300311
Kirill Timofeeva5186962017-10-25 14:25:47 +0300312apply plugin: 'base'
313
314clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300315
316// --------------- Knit configuration ---------------
317
318apply plugin: 'kotlinx-knit'
319
320knit {
321 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
322 moduleRoots = [".", "integration", "reactive", "ui"]
323}
324
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300325knitPrepare.dependsOn getTasksByName("dokka", true)