blob: 187ce662c809b94c0044b66f6e5fb378f0d14e3a [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" }
17 maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
Roman Elizarov65eff0b2017-12-20 15:51:31 +030018 maven { url "https://plugins.gradle.org/m2/" }
Kirill Timofeeva5186962017-10-25 14:25:47 +030019 }
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030020 configurations.classpath {
21 resolutionStrategy {
22 eachDependency { DependencyResolveDetails details ->
23 if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name != 'kotlin-native-gradle-plugin') {
24 // fix version of all dependencies from org.jetbrains.kotlin group
25 // even when other dependencies require other versions indirectly,
26 // except kotlin-native, which has its own pre-release versioning
27 details.useVersion kotlin_version
28 }
29 }
30 }
31 }
Kirill Timofeeva5186962017-10-25 14:25:47 +030032 dependencies {
33 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Roman Elizarov31452902018-04-11 13:58:19 +030034 classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
Kirill Timofeeva5186962017-10-25 14:25:47 +030035 classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
36 classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFU_version"
Roman Elizarov65eff0b2017-12-20 15:51:31 +030037 classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
38 classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
Vsevolod Tolstopyatov305c66a2018-08-21 21:01:58 +030039
40 // JMH plugins
41 classpath "com.github.jengelman.gradle.plugins:shadow:2.0.2"
42 classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.7"
43 classpath "net.ltgt.gradle:gradle-apt-plugin:0.10"
Kirill Timofeeva5186962017-10-25 14:25:47 +030044 }
45}
46
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030047allprojects {
48 def deployVersion = properties['DeployVersion']
49 if (deployVersion != null) version = deployVersion
50 if (useKotlinSnapshot) {
51 kotlin_version = '1.2-SNAPSHOT'
52 }
Roman Elizarov18fa1162018-06-27 15:13:01 +030053
54 repositories {
55 jcenter()
56 maven { url "https://kotlin.bintray.com/kotlin-dev" }
57 maven { url "https://kotlin.bintray.com/kotlinx" }
58 }
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030059}
60
61
Roman Elizarov38b6fd32018-01-17 10:12:23 +030062// Report Kotlin compiler version when building project
63println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
64
Kirill Timofeeva5186962017-10-25 14:25:47 +030065// --------------- Configure sub-projects with Kotlin sources ---------------
66
67def sourceless = ['site']
68
Roman Elizarove1c0b652017-12-01 14:02:57 +030069static def platformOf(project) {
70 if (project.name.endsWith("-common")) return "common"
71 if (project.name.endsWith("-js")) return "js"
Roman Elizarov31452902018-04-11 13:58:19 +030072 if (project.name.endsWith("-native")) return "native"
Roman Elizarove1c0b652017-12-01 14:02:57 +030073 return "jvm"
74}
Kirill Timofeeva5186962017-10-25 14:25:47 +030075
Roman Elizarove1c0b652017-12-01 14:02:57 +030076static def platformLib(base, platform) {
77 if (platform == "jvm") return base
78 return "$base-$platform"
79}
80
Ilya Gorbunovb1a07ee2018-04-16 21:51:55 +030081subprojects {
82 if (useKotlinSnapshot) {
83 repositories {
84 maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
85 }
86 }
87 configurations.all {
88 resolutionStrategy {
89 eachDependency { DependencyResolveDetails details ->
90 if (details.requested.group == 'org.jetbrains.kotlin') {
91 details.useVersion kotlin_version
92 }
93 }
94 }
95 }
96}
97
Roman Elizarove1c0b652017-12-01 14:02:57 +030098configure(subprojects.findAll { !sourceless.contains(it.name) }) {
99 def platform = platformOf(it)
Roman Elizarove1a56522018-04-04 10:31:08 +0300100 apply from: rootProject.file("gradle/compile-${platform}.gradle")
Kirill Timofeeva5186962017-10-25 14:25:47 +0300101}
102
103// --------------- Configure sub-projects that are part of the library ---------------
104
Vsevolod Tolstopyatov74bcc922018-05-03 20:07:54 +0300105def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'binary-compatibility-validator']
Kirill Timofeeva5186962017-10-25 14:25:47 +0300106
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300107// Reconfigure source sets to avoid long "src/main/kotlin/fqn"
108configure(subprojects.findAll { !it.name.contains(sourceless) && it.name != "benchmarks" }) {
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300109 def projectName = it.name
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300110 sourceSets {
Roman Elizarovf9408f62018-06-29 20:12:52 +0300111 main.kotlin.srcDirs = ['src']
112 test.kotlin.srcDirs = ['test']
Roman Elizarov7587eba2018-07-25 12:22:46 +0300113 // todo: do we still need this workaround?
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300114 if (!projectName.endsWith("-native")) {
115 main.resources.srcDirs = ['resources']
Roman Elizarov7587eba2018-07-25 12:22:46 +0300116 test.resources.srcDirs = ['test-resources']
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300117 }
Vsevolod Tolstopyatove1fa1972018-06-19 15:54:58 +0300118 }
119}
120
Roman Elizarov31452902018-04-11 13:58:19 +0300121// configure atomicfu
122configure(subprojects.findAll { !internal.contains(it.name) }) {
123 def platform = platformOf(it)
124 apply from: rootProject.file("gradle/atomicfu-${platform}.gradle")
Kirill Timofeeva5186962017-10-25 14:25:47 +0300125}
126
Roman Elizarove1c0b652017-12-01 14:02:57 +0300127// configure dependencies on core
128configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotlinx-coroutines-core-common'}) {
129 def platform = platformOf(it)
130 def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
131
132 if (it.name == coroutines_core) {
133 dependencies {
134 expectedBy project(':kotlinx-coroutines-core-common')
135 }
136 } else {
137 dependencies {
138 compile project(":$coroutines_core")
139 //the only way IDEA can resolve test classes
140 testCompile project(":$coroutines_core").sourceSets.test.output
141 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300142 }
143}
144
145// --------------- Configure sub-projects that are published ---------------
146
Roman Elizarov31452902018-04-11 13:58:19 +0300147// todo: native is not published yet
Vsevolod Tolstopyatov4ddfc912018-07-12 18:36:02 +0300148def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js']
Kirill Timofeeva5186962017-10-25 14:25:47 +0300149
150def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/"
151def core_docs_file = "$projectDir/core/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
152
153configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300154 apply from: rootProject.file('gradle/dokka.gradle')
155 apply from: rootProject.file('gradle/publish-bintray.gradle')
Kirill Timofeeva5186962017-10-25 14:25:47 +0300156}
157
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300158configure(subprojects.findAll { !unpublished.contains(it.name) }) {
Roman Elizarove1c0b652017-12-01 14:02:57 +0300159 def platform = platformOf(it)
160 def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
161
Roman Elizarov65eff0b2017-12-20 15:51:31 +0300162 if (it.name != coroutines_core) {
163 dokka.dependsOn project(":$coroutines_core").dokka
164
165 tasks.withType(dokka.getClass()) {
166 externalDocumentationLink {
167 url = new URL(core_docs_url)
168 packageListUrl = new URL("file://$core_docs_file")
169 }
170 }
171 }
172
Roman Elizarove1c0b652017-12-01 14:02:57 +0300173 if (platform == "jvm") {
174 dokkaJavadoc.dependsOn project(":$coroutines_core").dokka
Roman Elizarovaa100ea2018-08-22 11:21:53 +0300175 // dump declarations from main JVM module for binary-compatibility-validator
176 compileKotlin {
Vsevolod Tolstopyatov74bcc922018-05-03 20:07:54 +0300177 kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
178 }
Roman Elizarove1c0b652017-12-01 14:02:57 +0300179 }
Kirill Timofeeva5186962017-10-25 14:25:47 +0300180}
181
Roman Elizarov94fb2a32018-03-05 17:32:59 +0300182// main deployment task
183task deploy(dependsOn: getTasksByName("bintrayUpload", true) + getTasksByName("publishNpm", true))
184
Kirill Timofeeva5186962017-10-25 14:25:47 +0300185apply plugin: 'base'
186
187clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }