blob: 20b03b3a10e707a78d68ef706feddf9c24ab8d13 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +03002 * Copyright 2016-2019 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
5
6apply from: rootProject.file("gradle/experimental.gradle")
7
8def rootModule = "kotlinx.coroutines"
9def coreModule = "kotlinx-coroutines-core"
10// Not applicable for Kotlin plugin
11def sourceless = ['kotlinx.coroutines', 'site']
12def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator']
13// Not published
14def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'android-unit-tests']
15
16static def platformOf(project) {
17 def name = project.name
18 if (name.endsWith("-js")) return "js"
19 if (name.endsWith("-common") || name.endsWith("-native")) {
20 throw IllegalStateException("$name platform is not supported")
21 }
22 return "jvm"
23}
Roman Elizarov1f74a2d2018-06-29 19:19:45 +030024
Kirill Timofeeva5186962017-10-25 14:25:47 +030025buildscript {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030026 /*
27 * These property group is used to build kotlinx.coroutines against Kotlin compiler snapshot.
28 * How does it work:
29 * When build_snapshot_train is set to true, kotlin_version property is overridden with kotlin_snapshot_version,
30 * atomicfu_version is overwritten by TeamCity environment (AFU is built with snapshot and published to mavenLocal
31 * as previous step or the snapshot build).
32 * Additionally, mavenLocal and Sonatype snapshots are added to repository list and stress tests are disabled.
33 * DO NOT change the name of these properties without adapting kotlinx.train build chain.
34 */
35 def prop = rootProject.properties['build_snapshot_train']
36 ext.build_snapshot_train = prop != null && prop != ""
37 if (build_snapshot_train) {
38 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
39 if (kotlin_version == null) {
40 throw new IllegalArgumentException("'kotlin_snapshot_version' should be defined when building with snapshot compiler")
41 }
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030042 repositories {
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030043 mavenLocal()
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030044 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
45 }
46 }
Kirill Timofeeva5186962017-10-25 14:25:47 +030047 repositories {
48 jcenter()
Roman Elizarov31452902018-04-11 13:58:19 +030049 maven { url "https://kotlin.bintray.com/kotlinx" }
50 maven { url "https://kotlin.bintray.com/kotlin-dev" }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030051 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov31452902018-04-11 13:58:19 +030052 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030053 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030054 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030055
Kirill Timofeeva5186962017-10-25 14:25:47 +030056 dependencies {
Vsevolod Tolstopyatov31796832018-11-12 14:49:41 +030057 classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$artifactory_plugin_version"
Kirill Timofeeva5186962017-10-25 14:25:47 +030058 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
59 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030060 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030061 classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
62 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030063
64 // JMH plugins
Vsevolod Tolstopyatov3781a822018-12-13 11:58:29 +030065 classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030066 classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.7"
67 classpath "net.ltgt.gradle:gradle-apt-plugin:0.10"
Kirill Timofeeva5186962017-10-25 14:25:47 +030068 }
69}
70
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030071allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030072 // the only place where HostManager could be instantiated
73 project.ext.hostManager = new HostManager()
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +030074 def deployVersion = properties['DeployVersion']
75 if (deployVersion != null) version = deployVersion
76
77 if (build_snapshot_train) {
78 ext.kotlin_version = rootProject.properties['kotlin_snapshot_version']
79 println "Using Kotlin $kotlin_version for project $it"
80
81 if (version != atomicfu_version) {
82 throw new IllegalStateException("Current deploy version is $version, but atomicfu version is not overridden ($atomicfu_version) for $it")
83 }
84
85 kotlin_version = rootProject.properties['kotlin_snapshot_version']
86 repositories {
87 mavenLocal()
88 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
89 }
90 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030091}
92
93allprojects {
94 apply plugin: 'kotlinx-atomicfu'
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030095 def projectName = it.name
Roman Elizarov18fa1162018-06-27 15:13:01 +030096 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +030097 /*
98 * google should be first in the repository list because some of the play services
99 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
100 */
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300101 if (projectName == "kotlinx-coroutines-play-services") {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +0300102 google()
103 }
Roman Elizarov18fa1162018-06-27 15:13:01 +0300104 jcenter()
Vsevolod Tolstopyatov8a45c472018-10-24 11:55:30 +0300105 maven { url "https://kotlin.bintray.com/kotlin-dev" }
Roman Elizarov0950dfa2018-07-13 10:33:25 +0300106 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov18fa1162018-06-27 15:13:01 +0300107 maven { url "https://kotlin.bintray.com/kotlinx" }
108 }
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300109
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300110 if (projectName == rootModule || projectName == coreModule) return
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +0300111
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300112 // Add dependency to core source sets. Core is configured in kx-core/build.gradle
113 evaluationDependsOn(":$coreModule")
114 if (sourceless.contains(projectName)) return
Roman Elizarov38b6fd32018-01-17 10:12:23 +0300115
Roman Elizarove1c0b652017-12-01 14:02:57 +0300116 def platform = platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300117 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300118
119
120 dependencies {
121 // See comment below for rationale, it will be replaced with "project" dependency
122 compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300123 compileOnly "org.jetbrains.kotlinx:atomicfu:$atomicfu_version"
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300124
125 // the only way IDEA can resolve test classes
126 testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
127 }
128
129 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
130 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
131 kotlinOptions.freeCompilerArgs += "-progressive"
132 // Binary compatibility support
133 kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
134 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300135}
136
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300137if (build_snapshot_train) {
138 println "Hacking test tasks, removing stress and flaky tests"
139 allprojects {
140 tasks.withType(Test).all {
Vsevolod Tolstopyatovdbe3f482019-04-17 17:51:13 +0300141 exclude '**/*LinearizabilityTest*'
142 exclude '**/*LFTest*'
143 exclude '**/*StressTest*'
144 exclude '**/*scheduling*'
145 exclude '**/*Timeout*'
Vsevolod Tolstopyatov1748ce12019-04-18 14:49:35 +0300146 exclude '**/*coroutines/debug*' // Unmute after 1.3.31 where inlining was fixed
147 exclude '**/*definitely/not/kotlinx*'
148 }
149 }
150
151 println "Manifest of kotlin-compiler-embeddable.jar for coroutines"
152 configure(subprojects.findAll { it.name == "kotlinx-coroutines-core" }) {
153 configurations.matching { it.name == "kotlinCompilerClasspath" }.all {
154 resolvedConfiguration.getFiles().findAll { it.name.contains("kotlin-compiler-embeddable") }.each {
155 def manifest = zipTree(it).matching {
156 include 'META-INF/MANIFEST.MF'
157 }.getFiles().first()
158
159 manifest.readLines().each {
160 println it
161 }
162 }
Vsevolod Tolstopyatov585b7662019-04-16 12:10:57 +0300163 }
164 }
165}
166
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300167/*
168 * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
169 * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
170 * for JVM-only projects.
171 *
172 * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
173 * to have out "project" dependency back.
174 */
175configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
176 configurations.all {
177 resolutionStrategy.dependencySubstitution {
178 substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
179 }
180 }
181}
Kirill Timofeeva5186962017-10-25 14:25:47 +0300182
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300183// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
184configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300185 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300186 main.kotlin.srcDirs = ['src']
187 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300188 main.resources.srcDirs = ['resources']
189 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300190 }
191}
192
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300193def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
194def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300195
196configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300197 apply from: rootProject.file('gradle/dokka.gradle')
198 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300199}
200
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300201configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300202 if (it.name != coreModule) {
203 dokka.dependsOn project(":$coreModule").dokka
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300204 tasks.withType(dokka.getClass()) {
205 externalDocumentationLink {
206 url = new URL(core_docs_url)
207 packageListUrl = new URL("file://$core_docs_file")
208 }
209 }
210 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300211
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300212 if (platformOf(it) == "jvm") {
213 dokkaJavadoc.dependsOn project(":$coreModule").dokka
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300214 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300215}
216
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300217// Report Kotlin compiler version when building project
218println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
219
220// --------------- Configure sub-projects that are published ---------------
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300221task deploy(dependsOn: getTasksByName("bintrayUpload", true) + getTasksByName("publishNpm", true))
222
Kirill Timofeeva5186962017-10-25 14:25:47 +0300223apply plugin: 'base'
224
225clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }