blob: a758393b6c4afc0e9880a60d611bc4e751d91364 [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 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
50 }
51 }
Roman Elizarove1ac2e52019-04-19 18:51:05 +030052
Kirill Timofeeva5186962017-10-25 14:25:47 +030053 repositories {
54 jcenter()
Roman Elizarov31452902018-04-11 13:58:19 +030055 maven { url "https://kotlin.bintray.com/kotlinx" }
Michael Kuzmin476d6de2019-12-16 22:38:59 +030056 maven {
57 url "https://kotlin.bintray.com/kotlin-dev"
58 credentials {
59 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
60 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
61 }
62 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030063 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov31452902018-04-11 13:58:19 +030064 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030065 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030066 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030067
Kirill Timofeeva5186962017-10-25 14:25:47 +030068 dependencies {
69 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
70 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030071 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov660c2d72020-02-14 13:18:37 +030072 classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030073 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +030074 classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030075
76 // JMH plugins
Vsevolod Tolstopyatovbda9c792019-09-12 16:50:33 +030077 classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
Kirill Timofeeva5186962017-10-25 14:25:47 +030078 }
79}
80
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030081import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
82
Sergey Igushkin17248c82020-05-22 12:28:25 +030083// Hierarchical project structures are not fully supported in 1.3.7x MPP, enable conditionally for 1.4.x
84if (VersionNumber.parse(kotlin_version) > VersionNumber.parse("1.3.79")) {
85 ext.set("kotlin.mpp.enableGranularSourceSetsMetadata", "true")
86}
87
Roman Elizarovd2f4b2b2019-09-02 17:22:39 +030088// todo:KLUDGE: This is needed to workaround dependency resolution between Java and MPP modules
89def configureKotlinJvmPlatform(configuration) {
90 configuration.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm)
91}
92
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030093allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030094 // the only place where HostManager could be instantiated
95 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030096 def deployVersion = properties['DeployVersion']
97 if (deployVersion != null) version = deployVersion
98
99 if (build_snapshot_train) {
100 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
101 println "Using Kotlin $kotlin_version for project $it"
102
Vsevolod Tolstopyatov6ca6ed52019-08-21 17:08:34 +0300103 def skipSnapshotChecks = rootProject.properties['skip_snapshot_checks'] != null
104 if (!skipSnapshotChecks && version != atomicfu_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300105 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
106 }
107
108 kotlin_version = rootProject.properties['kotlin_snapshot_version']
Roman Elizarove1ac2e52019-04-19 18:51:05 +0300109 }
110
Roman Elizarov660c2d72020-02-14 13:18:37 +0300111 if (using_snapshot_version) {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300112 repositories {
113 mavenLocal()
114 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
115 }
116 }
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300117
118 ext.unpublished = unpublished
Roman Elizarov0b16abf2019-09-03 11:07:11 +0300119
120 // This project property is set during nightly stress test
121 def stressTest = project.properties['stressTest']
122
123 // Copy it to all test tasks
124 tasks.withType(Test) {
125 systemProperty 'stressTest', stressTest
126 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300127}
128
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300129apply plugin: "binary-compatibility-validator"
130apiValidation {
dkhalanskyjb36512762020-02-21 17:31:05 +0300131 ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300132 if (build_snapshot_train) {
133 ignoredProjects.remove("site")
134 ignoredProjects.remove("example-frontend-js")
Stanislav Erokhin4b16e1b2020-06-09 09:38:51 +0300135 ignoredProjects.add("kotlinx-coroutines-core")
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300136 }
Vsevolod Tolstopyatove1538632020-02-10 21:12:58 +0300137 ignoredPackages += "kotlinx.coroutines.internal"
138}
139
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300140// Configure repositories
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300141allprojects {
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300142 String projectName = it.name
Roman Elizarov18fa1162018-06-27 15:13:01 +0300143 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300144 /*
145 * google should be first in the repository list because some of the play services
146 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
147 */
Roman Elizarov660c2d72020-02-14 13:18:37 +0300148 google()
Roman Elizarov18fa1162018-06-27 15:13:01 +0300149 jcenter()
Michael Kuzmin476d6de2019-12-16 22:38:59 +0300150 maven {
151 url "https://kotlin.bintray.com/kotlin-dev"
152 credentials {
153 username = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER') ?: ""
154 password = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') ?: ""
155 }
156 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +0300157 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov18fa1162018-06-27 15:13:01 +0300158 maven { url "https://kotlin.bintray.com/kotlinx" }
159 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300160}
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300161
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300162// Add dependency to core source sets. Core is configured in kx-core/build.gradle
163configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != coreModule }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300164 evaluationDependsOn(":$coreModule")
Victor Turanskyde388902020-05-02 14:22:30 +0300165 def platform = PlatformKt.platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300166 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300167 dependencies {
168 // See comment below for rationale, it will be replaced with "project" dependency
169 compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300170 // the only way IDEA can resolve test classes
171 testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
172 }
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300173}
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300174
Roman Elizarovbf9509d2020-02-14 15:52:10 +0300175// Configure subprojects with Kotlin sources
176configure(subprojects.findAll { !sourceless.contains(it.name) }) {
177 // Use atomicfu plugin, it also adds all the necessary dependencies
178 apply plugin: 'kotlinx-atomicfu'
179
180 // Configure options for all Kotlin compilation tasks
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300181 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
182 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
183 kotlinOptions.freeCompilerArgs += "-progressive"
Vsevolod Tolstopyatova8904e22019-07-17 17:22:05 -0700184 kotlinOptions.freeCompilerArgs += "-XXLanguage:+InlineClasses"
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/*
224 * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
225 * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
226 * for JVM-only projects.
227 *
Victor Turanskya8f4b642020-04-28 14:30:02 +0300228 * 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 +0300229 * to have out "project" dependency back.
230 */
231configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
232 configurations.all {
233 resolutionStrategy.dependencySubstitution {
234 substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
235 }
236 }
237}
Kirill Timofeeva5186962017-10-25 14:25:47 +0300238
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300239// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
240configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300241 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300242 main.kotlin.srcDirs = ['src']
243 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300244 main.resources.srcDirs = ['resources']
245 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300246 }
247}
248
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300249def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
250def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300251
252configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300253 if (it.name != 'kotlinx-coroutines-bom') {
254 apply from: rootProject.file('gradle/dokka.gradle')
255 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300256 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300257}
258
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300259configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300260 if (it.name != "kotlinx-coroutines-bom") {
261 if (it.name != coreModule) {
262 dokka.dependsOn project(":$coreModule").dokka
263 tasks.withType(dokka.getClass()) {
264 externalDocumentationLink {
265 url = new URL(core_docs_url)
Roman Elizarov660c2d72020-02-14 13:18:37 +0300266 packageListUrl = new File(core_docs_file).toURI().toURL()
Vsevolod Tolstopyatovfe4e05c2019-07-19 12:28:15 +0300267 }
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300268 }
269 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300270 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300271}
272
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300273// Report Kotlin compiler version when building project
274println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
275
276// --------------- Configure sub-projects that are published ---------------
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300277def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
278
Roman Elizarov1ac3dc22020-02-14 15:39:09 +0300279task deploy(dependsOn: publishTasks)
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300280
Kirill Timofeeva5186962017-10-25 14:25:47 +0300281apply plugin: 'base'
282
283clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
Roman Elizarov660c2d72020-02-14 13:18:37 +0300284
285// --------------- Knit configuration ---------------
286
287apply plugin: 'kotlinx-knit'
288
289knit {
290 siteRoot = "https://kotlin.github.io/kotlinx.coroutines"
291 moduleRoots = [".", "integration", "reactive", "ui"]
292}
293
Vsevolod Tolstopyatovaff82022020-03-10 19:58:36 +0300294knitPrepare.dependsOn getTasksByName("dokka", true)