blob: a9781d4647f3e330ce89baccd154701ce1c3b037 [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 {
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030026 ext.useKotlinSnapshot = rootProject.properties['kotlinSnapshot'] != null
27 if (useKotlinSnapshot) {
Roman Elizarovdadd50c2017-12-21 17:34:12 +030028 ext.kotlin_version = '1.2-SNAPSHOT'
Roman Elizarov1f6b44d2017-10-26 17:51:52 +030029 repositories {
30 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
31 }
32 }
Kirill Timofeeva5186962017-10-25 14:25:47 +030033 repositories {
34 jcenter()
Roman Elizarov31452902018-04-11 13:58:19 +030035 maven { url "https://kotlin.bintray.com/kotlinx" }
36 maven { url "https://kotlin.bintray.com/kotlin-dev" }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030037 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov31452902018-04-11 13:58:19 +030038 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030039 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030040 }
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030041
Kirill Timofeeva5186962017-10-25 14:25:47 +030042 dependencies {
Vsevolod Tolstopyatov31796832018-11-12 14:49:41 +030043 classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$artifactory_plugin_version"
Kirill Timofeeva5186962017-10-25 14:25:47 +030044 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
45 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
46 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFU_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030047 classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
48 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030049
50 // JMH plugins
Vsevolod Tolstopyatov3781a822018-12-13 11:58:29 +030051 classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030052 classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.7"
53 classpath "net.ltgt.gradle:gradle-apt-plugin:0.10"
Kirill Timofeeva5186962017-10-25 14:25:47 +030054 }
55}
56
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030057allprojects {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030058 // the only place where HostManager could be instantiated
59 project.ext.hostManager = new HostManager()
60}
61
62allprojects {
63 apply plugin: 'kotlinx-atomicfu'
64
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030065 def deployVersion = properties['DeployVersion']
66 if (deployVersion != null) version = deployVersion
67 if (useKotlinSnapshot) {
68 kotlin_version = '1.2-SNAPSHOT'
69 }
Roman Elizarov18fa1162018-06-27 15:13:01 +030070
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030071 def projectName = it.name
Roman Elizarov18fa1162018-06-27 15:13:01 +030072 repositories {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +030073 /*
74 * google should be first in the repository list because some of the play services
75 * transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
76 */
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030077 if (projectName == "kotlinx-coroutines-play-services") {
Vsevolod Tolstopyatov6f01c932018-10-23 19:40:48 +030078 google()
79 }
Roman Elizarov18fa1162018-06-27 15:13:01 +030080 jcenter()
Vsevolod Tolstopyatov8a45c472018-10-24 11:55:30 +030081 maven { url "https://kotlin.bintray.com/kotlin-dev" }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030082 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov18fa1162018-06-27 15:13:01 +030083 maven { url "https://kotlin.bintray.com/kotlinx" }
84 }
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030085
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030086 if (projectName == rootModule || projectName == coreModule) return
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030087
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030088 // Add dependency to core source sets. Core is configured in kx-core/build.gradle
89 evaluationDependsOn(":$coreModule")
90 if (sourceless.contains(projectName)) return
Roman Elizarov38b6fd32018-01-17 10:12:23 +030091
Roman Elizarove1c0b652017-12-01 14:02:57 +030092 def platform = platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +030093 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +030094
95
96 dependencies {
97 // See comment below for rationale, it will be replaced with "project" dependency
98 compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
99 compileOnly "org.jetbrains.kotlinx:atomicfu:$atomicFU_version"
100
101 // the only way IDEA can resolve test classes
102 testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
103 }
104
105 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
106 kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
107 kotlinOptions.freeCompilerArgs += "-progressive"
108 // Binary compatibility support
109 kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
110 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300111}
112
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300113/*
114 * Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
115 * but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
116 * for JVM-only projects.
117 *
118 * We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
119 * to have out "project" dependency back.
120 */
121configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
122 configurations.all {
123 resolutionStrategy.dependencySubstitution {
124 substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
125 }
126 }
127}
Kirill Timofeeva5186962017-10-25 14:25:47 +0300128
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300129// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
130configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300131 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300132 main.kotlin.srcDirs = ['src']
133 test.kotlin.srcDirs = ['test']
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300134 main.resources.srcDirs = ['resources']
135 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300136 }
137}
138
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300139def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
140def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Kirill Timofeeva5186962017-10-25 14:25:47 +0300141
142configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300143 apply from: rootProject.file('gradle/dokka.gradle')
144 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300145}
146
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300147configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300148 if (it.name != coreModule) {
149 dokka.dependsOn project(":$coreModule").dokka
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300150 tasks.withType(dokka.getClass()) {
151 externalDocumentationLink {
152 url = new URL(core_docs_url)
153 packageListUrl = new URL("file://$core_docs_file")
154 }
155 }
156 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300157
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300158 if (platformOf(it) == "jvm") {
159 dokkaJavadoc.dependsOn project(":$coreModule").dokka
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300160 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300161}
162
Vsevolod Tolstopyatove50a0fa2019-01-28 11:34:24 +0300163
164// Report Kotlin compiler version when building project
165println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
166
167// --------------- Configure sub-projects that are published ---------------
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300168task deploy(dependsOn: getTasksByName("bintrayUpload", true) + getTasksByName("publishNpm", true))
169
Kirill Timofeeva5186962017-10-25 14:25:47 +0300170apply plugin: 'base'
171
172clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }