blob: beb6e2df4fd2c66502209e18b1da7b0b94fbcdda [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Kirill Timofeeva5186962017-10-25 14:25:47 +03005buildscript {
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +03006 ext.useKotlinSnapshot = rootProject.properties['kotlinSnapshot'] != null
7 if (useKotlinSnapshot) {
Roman Elizarovdadd50c2017-12-21 17:34:12 +03008 ext.kotlin_version = '1.2-SNAPSHOT'
Roman Elizarov1f6b44d2017-10-26 17:51:52 +03009 repositories {
10 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
11 }
12 }
Kirill Timofeeva5186962017-10-25 14:25:47 +030013 repositories {
14 jcenter()
Roman Elizarov31452902018-04-11 13:58:19 +030015 maven { url "https://kotlin.bintray.com/kotlinx" }
16 maven { url "https://kotlin.bintray.com/kotlin-dev" }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030017 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov31452902018-04-11 13:58:19 +030018 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030019 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030020 }
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030021 configurations.classpath {
22 resolutionStrategy {
23 eachDependency { DependencyResolveDetails details ->
24 if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name != 'kotlin-native-gradle-plugin') {
25 // fix version of all dependencies from org.jetbrains.kotlin group
26 // even when other dependencies require other versions indirectly,
27 // except kotlin-native, which has its own pre-release versioning
28 details.useVersion kotlin_version
29 }
30 }
31 }
32 }
Kirill Timofeeva5186962017-10-25 14:25:47 +030033 dependencies {
34 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Roman Elizarov31452902018-04-11 13:58:19 +030035 classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
Kirill Timofeeva5186962017-10-25 14:25:47 +030036 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
37 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFU_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030038 classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
39 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030040
41 // JMH plugins
42 classpath "com.github.jengelman.gradle.plugins:shadow:2.0.2"
43 classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.7"
44 classpath "net.ltgt.gradle:gradle-apt-plugin:0.10"
Kirill Timofeeva5186962017-10-25 14:25:47 +030045 }
46}
47
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030048allprojects {
49 def deployVersion = properties['DeployVersion']
50 if (deployVersion != null) version = deployVersion
51 if (useKotlinSnapshot) {
52 kotlin_version = '1.2-SNAPSHOT'
53 }
Roman Elizarov18fa1162018-06-27 15:13:01 +030054
55 repositories {
56 jcenter()
Roman Elizarov0950dfa2018-07-13 10:33:25 +030057 maven { url "https://kotlin.bintray.com/kotlin-eap" }
Roman Elizarov18fa1162018-06-27 15:13:01 +030058 maven { url "https://kotlin.bintray.com/kotlinx" }
59 }
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030060}
61
62
Roman Elizarov38b6fd32018-01-17 10:12:23 +030063// Report Kotlin compiler version when building project
64println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
65
Kirill Timofeeva5186962017-10-25 14:25:47 +030066// --------------- Configure sub-projects with Kotlin sources ---------------
67
68def sourceless = ['site']
69
Roman Elizarove1c0b652017-12-01 14:02:57 +030070static def platformOf(project) {
71 if (project.name.endsWith("-common")) return "common"
72 if (project.name.endsWith("-js")) return "js"
Roman Elizarov31452902018-04-11 13:58:19 +030073 if (project.name.endsWith("-native")) return "native"
Roman Elizarove1c0b652017-12-01 14:02:57 +030074 return "jvm"
75}
Kirill Timofeeva5186962017-10-25 14:25:47 +030076
Roman Elizarove1c0b652017-12-01 14:02:57 +030077static def platformLib(base, platform) {
78 if (platform == "jvm") return base
79 return "$base-$platform"
80}
81
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030082subprojects {
83 if (useKotlinSnapshot) {
84 repositories {
85 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
86 }
87 }
88 configurations.all {
89 resolutionStrategy {
90 eachDependency { DependencyResolveDetails details ->
91 if (details.requested.group == 'org.jetbrains.kotlin') {
92 details.useVersion kotlin_version
93 }
94 }
95 }
96 }
97}
98
Roman Elizarove1c0b652017-12-01 14:02:57 +030099configure(subprojects.findAll { !sourceless.contains(it.name) }) {
100 def platform = platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300101 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Kirill Timofeeva5186962017-10-25 14:25:47 +0300102}
103
104// --------------- Configure sub-projects that are part of the library ---------------
105
Vsevolod Tolstopyatov74bcc922018-05-03 20:07:54 +0300106def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'binary-compatibility-validator']
Kirill Timofeeva5186962017-10-25 14:25:47 +0300107
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300108// Reconfigure source sets to avoid long "src/main/kotlin/fqn"
109configure(subprojects.findAll { !it.name.contains(sourceless) && it.name != "benchmarks" }) {
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300110 def projectName = it.name
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300111 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300112 main.kotlin.srcDirs = ['src']
113 test.kotlin.srcDirs = ['test']
Roman Elizarov7587eba2018-07-25 12:22:46 +0300114 // todo: do we still need this workaround?
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300115 if (!projectName.endsWith("-native")) {
116 main.resources.srcDirs = ['resources']
Roman Elizarov7587eba2018-07-25 12:22:46 +0300117 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300118 }
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300119 }
120}
121
Roman Elizarov31452902018-04-11 13:58:19 +0300122// configure atomicfu
123configure(subprojects.findAll { !internal.contains(it.name) }) {
124 def platform = platformOf(it)
125 apply from: rootProject.file("gradle/atomicfu-${platform}.gradle")
Kirill Timofeeva5186962017-10-25 14:25:47 +0300126}
127
Roman Elizarove1c0b652017-12-01 14:02:57 +0300128// configure dependencies on core
129configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotlinx-coroutines-core-common'}) {
130 def platform = platformOf(it)
131 def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
132
133 if (it.name == coroutines_core) {
134 dependencies {
135 expectedBy project(':kotlinx-coroutines-core-common')
136 }
137 } else {
138 dependencies {
139 compile project(":$coroutines_core")
140 //the only way IDEA can resolve test classes
141 testCompile project(":$coroutines_core").sourceSets.test.output
142 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300143 }
144}
145
146// --------------- Configure sub-projects that are published ---------------
147
Roman Elizarov31452902018-04-11 13:58:19 +0300148// todo: native is not published yet
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300149def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js']
Kirill Timofeeva5186962017-10-25 14:25:47 +0300150
151def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/"
152def core_docs_file = "$projectDir/core/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
153
154configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300155 apply from: rootProject.file('gradle/dokka.gradle')
156 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300157}
158
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300159configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Roman Elizarove1c0b652017-12-01 14:02:57 +0300160 def platform = platformOf(it)
161 def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
162
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300163 if (it.name != coroutines_core) {
164 dokka.dependsOn project(":$coroutines_core").dokka
165
166 tasks.withType(dokka.getClass()) {
167 externalDocumentationLink {
168 url = new URL(core_docs_url)
169 packageListUrl = new URL("file://$core_docs_file")
170 }
171 }
172 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300173
Roman Elizarove1c0b652017-12-01 14:02:57 +0300174 if (platform == "jvm") {
175 dokkaJavadoc.dependsOn project(":$coroutines_core").dokka
Roman Elizarovaa100ea2018-08-22 11:21:53 +0300176 // dump declarations from main JVM module for binary-compatibility-validator
177 compileKotlin {
Vsevolod Tolstopyatov74bcc922018-05-03 20:07:54 +0300178 kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
179 }
Roman Elizarove1c0b652017-12-01 14:02:57 +0300180 }
Vsevolod Tolstopyatove6e82392018-10-09 19:06:29 +0300181
182
183 tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
184 kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.Experimental",
185 "-Xuse-experimental=kotlin.experimental.ExperimentalTypeInference",
186 "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
187 "-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi",
188 "-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi"]
189
190 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300191}
192
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300193// main deployment task
194task deploy(dependsOn: getTasksByName("bintrayUpload", true) + getTasksByName("publishNpm", true))
195
Kirill Timofeeva5186962017-10-25 14:25:47 +0300196apply plugin: 'base'
197
198clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }