blob: 938d42e7a17d3dfae7f4d8fa1fe875d4bbd4930d [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 }
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 {
57 jcenter()
Vsevolod Tolstopyatov2d0d9aa2020-08-13 15:34:49 +030058 maven {
59 url "https://kotlin.bintray.com/kotlinx"
60 credentials {
61 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
62 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
63 }
64 }
Vsevolod Tolstopyatov63156a82020-08-24 16:15:52 +030065 // Future replacement for kotlin-dev, with cache redirector
66 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Michael Kuzmin476d6de2019-12-16 22:38:59 +030067 maven {
68 url "https://kotlin.bintray.com/kotlin-dev"
69 credentials {
70 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
71 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
72 }
73 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030074 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov31452902018-04-11 13:58:19 +030075 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030076 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030077 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030078
Kirill Timofeeva5186962017-10-25 14:25:47 +030079 dependencies {
80 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
81 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030082 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov660c2d72020-02-14 13:18:37 +030083 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030084 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030085 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030086
87 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030088 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
Kirill Timofeeva5186962017-10-25 14:25:47 +030089 }
Roman Elizarov85b1a2b2020-09-14 17:48:17 +030090
91 CacheRedirector.configureBuildScript(buildscript, rootProject)
Kirill Timofeeva5186962017-10-25 14:25:47 +030092}
93
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030094import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
95
Roman Elizarov738f5a22020-10-12 19:03:46 +030096// todo:KLUDGE: Hierarchical project structures are not fully supported in IDEA, enable only for a regular built
97if (!Idea.active) {
Sergey Igushkin17248c82020-05-22 12:28:25 +030098 ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
99}
100
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +0300101// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
102def configureKotlinJvmPlatform(configuration) {
103 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
104}
105
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300106allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300107 // the only place where HostManager could be instantiated
108 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300109 def deployVersion = properties['DeployVersion']
110 if (deployVersion != null) version = deployVersion
111
112 if (build_snapshot_train) {
113 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
114 println "Using Kotlin $kotlin_version for project $it"
115
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +0300116 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
117 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300118 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
119 }
120
121 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300122 }
123
Roman Elizarov660c2d72020-02-14 13:18:37 +0300124 if (using_snapshot_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300125 repositories {
126 mavenLocal()
127 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
128 }
129 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300130
131 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300132
133 // This project property is set during nightly stress test
134 def stressTest = project.properties['stressTest']
135
136 // Copy it to all test tasks
137 tasks.withType(Test) {
138 systemProperty 'stressTest', stressTest
139 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300140}
141
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300142apply plugin: "binary-compatibility-validator"
143apiValidation {
dkhalanskyjb36512762020-02-21 17:31:05 +0300144 ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300145 if (build_snapshot_train) {
146 ignoredProjects.remove("site")
147 ignoredProjects.remove("example-frontend-js")
Stanislav Erokhin4b16e1b2020-06-09 09:38:51 +0300148 ignoredProjects.add("kotlinx-coroutines-core")
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300149 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300150 ignoredPackages += "kotlinx.coroutines.internal"
151}
152
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300153// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300154allprojects {
Roman Elizarov18fa1162018-06-27 15:13:01 +0300155 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300156 /*
157 * google should be first in the repository list because some of the play services
158 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
159 */
Roman Elizarov660c2d72020-02-14 13:18:37 +0300160 google()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300161 jcenter()
Vsevolod Tolstopyatov63156a82020-08-24 16:15:52 +0300162 // Future replacement for kotlin-dev, with cache redirector
163 maven { url "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" }
Michael Kuzmin476d6de2019-12-16 22:38:59 +0300164 maven {
165 url "https://kotlin.bintray.com/kotlin-dev"
166 credentials {
167 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
168 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
169 }
170 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +0300171 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Vsevolod Tolstopyatov2d0d9aa2020-08-13 15:34:49 +0300172 maven {
173 url "https://kotlin.bintray.com/kotlinx"
174 credentials {
175 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
176 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
177 }
178 }
179 mavenLocal()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300180 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300181}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300182
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300183// Add dependency to core source sets. Core is configured in kx-core/build.gradle
184configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300185 evaluationDependsOn(":$coreModule")
Victor Turanskyde388902020-05-02 14:22:30 +0300186 def platform = PlatformKt.platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300187 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300188 dependencies {
189 // See comment below for rationale, it will be replaced with "project" dependency
190 compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300191 // the only way IDEA can resolve test classes
192 testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
193 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300194}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300195
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300196// Configure subprojects with Kotlin sources
197configure(subprojects.findAll { !sourceless.contains(it.name) }) {
198 // Use atomicfu plugin, it also adds all the necessary dependencies
199 apply plugin: 'kotlinx-atomicfu'
200
201 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300202 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
203 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
204 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700205 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300206 // Remove null assertions to get smaller bytecode on Android
207 kotlinOptions.freeCompilerArgs += ["-Xno-param-assertions", "-Xno-receiver-assertions", "-Xno-call-assertions"]
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300208 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300209}
210
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300211if (build_snapshot_train) {
212 println "Hacking test tasks, removing stress and flaky tests"
213 allprojects {
214 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300215 exclude '**/*LinearizabilityTest*'
216 exclude '**/*LFTest*'
217 exclude '**/*StressTest*'
218 exclude '**/*scheduling*'
219 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300220 exclude '**/*definitely/not/kotlinx*'
Vsevolod Tolstopyatov642989e2020-01-24 20:00:46 +0300221 // Disable because of KT-11567 in 1.4
Vsevolod Tolstopyatovfb990b02020-02-04 17:11:47 +0300222 exclude '**/*CasesPublicAPITest*'
Sergey Igushkin17248c82020-05-22 12:28:25 +0300223 // Kotlin
224 exclude '**/*PrecompiledDebugProbesTest*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300225 }
226 }
227
228 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
229 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
230 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
231 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
232 def manifest = zipTree(it).matching {
233 include 'META-INF/MANIFEST.MF'
234 }.getFiles().first()
235
236 manifest.readLines().each {
237 println it
238 }
239 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300240 }
241 }
242}
243
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300244/*
245 * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
246 * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
247 * for JVM-only projects.
248 *
Victor Turanskya8f4b642020-04-28 14:30:02 +0300249 * 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 +0300250 * to have out "project" dependency back.
251 */
252configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
253 configurations.all {
254 resolutionStrategy.dependencySubstitution {
255 substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
256 }
257 }
258}
Kirill Timofeeva5186962017-10-25 14:25:47 +0300259
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300260// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
Vsevolod Tolstopyatovfcaa6df2020-08-24 18:57:22 +0300261configure(subprojects.findAll {
262 !sourceless.contains(it.name) &&
263 it.name != "benchmarks" &&
264 it.name != coreModule &&
265 it.name != "example-frontend-js"
266}) {
267 // Pure JS and pure MPP doesn't have this notion and are configured separately
268 // TODO detect it via platformOf and migrate benchmarks to the same scheme
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300269 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300270 main.kotlin.srcDirs = ['src']
271 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300272 main.resources.srcDirs = ['resources']
273 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300274 }
275}
276
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300277def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
278def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300279
280configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300281 if (it.name != 'kotlinx-coroutines-bom') {
282 apply from: rootProject.file('gradle/dokka.gradle')
283 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300284 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300285}
286
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300287configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300288 if (it.name != "kotlinx-coroutines-bom") {
289 if (it.name != coreModule) {
290 dokka.dependsOn project(":$coreModule").dokka
291 tasks.withType(dokka.getClass()) {
292 externalDocumentationLink {
293 url = new URL(core_docs_url)
Roman Elizarov660c2d72020-02-14 13:18:37 +0300294 packageListUrl = new File(core_docs_file).toURI().toURL()
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300295 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300296 }
297 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300298 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300299}
300
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300301// Report Kotlin compiler version when building project
302println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
303
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300304// --------------- Cache redirector ---------------
305
306allprojects {
307 CacheRedirector.configure(project)
308}
309
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300310// --------------- Configure sub-projects that are published ---------------
Roman Elizarov85b1a2b2020-09-14 17:48:17 +0300311
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300312def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
313
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300314task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300315
Kirill Timofeeva5186962017-10-25 14:25:47 +0300316apply plugin: 'base'
317
318clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300319
320// --------------- Knit configuration ---------------
321
322apply plugin: 'kotlinx-knit'
323
324knit {
325 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
326 moduleRoots = [".", "integration", "reactive", "ui"]
327}
328
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300329knitPrepare.dependsOn getTasksByName("dokka", true)
Alexander Likhachev179f1422020-11-18 17:54:33 +0300330
331// Disable binary compatibility check for JVM IR compiler output by default
332if (jvm_ir_enabled) {
333 subprojects { project ->
334 configure(tasks.matching { it.name == "apiCheck" }) {
335 enabled = enabled && jvm_ir_api_check_enabled
336 }
337 }
338}