Skip to content

Commit e50a0fa

Browse files
authored
Migration to new multiplatorm plugin (#947)
Migration to a new multiplatform plugin * kotlinx-coroutines-core-[common|js|native] are merged into one core module with multiple source sets * Folder structure and readme are restructured * Publication process is patched to preserve backward compatibility with artifact names
1 parent 042b209 commit e50a0fa

File tree

462 files changed

+715
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

462 files changed

+715
-600
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ GlobalScope.launch {
1919

2020
## Modules
2121

22-
* [common](common/README.md) — common coroutines across all platforms:
22+
* [core](kotlinx-coroutines-core/README.md) — common coroutines across all platforms:
2323
* `launch` and `async` coroutine builders;
2424
* `Job` and `Deferred` light-weight future with cancellation support;
2525
* `MainScope` for Android and UI applications.
@@ -29,15 +29,16 @@ GlobalScope.launch {
2929
* `coroutineScope` and `supervisorScope` scope builders;
3030
* `SupervisorJob` and `CoroutineExceptionHandler` for supervision of coroutines hierarchies;
3131
* `select` expression support and more.
32-
* [core](core/README.md) — Kotlin/JVM implementation of common coroutines with additional features:
32+
* [core/jvm](kotlinx-coroutines-core/jvm/) — additional core features available on Kotlin/JVM:
3333
* `Dispatchers.IO` dispatcher for blocking coroutines;
3434
* `Executor.asCoroutineDispatcher()` extension, custom thread pools, and more.
35-
* [test](core/README.md) — test utilities for coroutines
35+
* [core/js](kotlinx-coroutines-core/js/) — additional core features available on Kotlin/JS:
36+
* Integration with `Promise`;
37+
* Integration with `Window`.
38+
* [test](kotlinx-coroutines-test/README.md) — test utilities for coroutines
3639
* `Dispatchers.setMain` to override `Dispatchers.Main` in tests.
37-
* [debug](core/README.md) — debug utilities for coroutines.
40+
* [debug](kotlinx-coroutines-debug/README.md) — debug utilities for coroutines.
3841
* `DebugProbes` API to probe, keep track of, print and dump active coroutines.
39-
* [js](js/README.md) — Kotlin/JS implementation of common coroutines with `Promise` support.
40-
* [native](native/README.md) — Kotlin/Native implementation of common coroutines with `runBlocking` single-threaded event loop.
4142
* [reactive](reactive/README.md) — modules that provide builders and iteration support for various reactive streams libraries:
4243
* Reactive Streams, RxJava 2.x, and Project Reactor.
4344
* [ui](ui/README.md) — modules that provide coroutine dispatchers for various single-threaded UI libraries:

benchmarks/build.gradle

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ repositories {
1212

1313
jmh.jmhVersion = '1.21'
1414

15+
jmh {
16+
duplicateClassesStrategy DuplicatesStrategy.INCLUDE
17+
}
18+
1519
jmhJar {
1620
baseName 'benchmarks'
1721
classifier = null
@@ -20,8 +24,8 @@ jmhJar {
2024
}
2125

2226
dependencies {
27+
compile "org.openjdk.jmh:jmh-core:1.21"
2328
compile 'com.typesafe.akka:akka-actor_2.12:2.5.0'
24-
compile project(':kotlinx-coroutines-core-common')
2529
compile project(':kotlinx-coroutines-core')
26-
compile "org.openjdk.jmh:jmh-core:1.21"
2730
}
31+

binary-compatibility-validator/resources/api.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
#
44

5-
module.roots=core integration native reactive ui test debug
5+
module.roots=/ integration reactive ui
66
module.marker=build.gradle
7-
module.ignore=kotlinx-coroutines-rx-example stdlib-stubs
7+
module.ignore=kotlinx-coroutines-rx-example stdlib-stubs benchmarks knit binary-compatibility-validator site
88

99
packages.internal=kotlinx.coroutines.internal

binary-compatibility-validator/test/PublicApiTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ class PublicApiTest(
6060
it matches regex
6161
&& !it.endsWith("-sources.jar")
6262
&& !it.endsWith("-javadoc.jar")
63-
&& !it.endsWith("-tests.jar")} }
63+
&& !it.endsWith("-tests.jar")}
64+
&& !it.name.contains("-metadata-")}
6465
return files.singleOrNull() ?: throw Exception("No single file matching $regex in $libsDir:\n${files.joinToString("\n")}")
6566
}
6667
}

build.gradle

+76-111
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
/*
2-
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
4+
import org.jetbrains.kotlin.konan.target.HostManager
5+
6+
apply from: rootProject.file("gradle/experimental.gradle")
7+
8+
def rootModule = "kotlinx.coroutines"
9+
def coreModule = "kotlinx-coroutines-core"
10+
// Not applicable for Kotlin plugin
11+
def sourceless = ['kotlinx.coroutines', 'site']
12+
def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator']
13+
// Not published
14+
def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'android-unit-tests']
15+
16+
static 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+
}
424

525
buildscript {
626
ext.useKotlinSnapshot = rootProject.properties['kotlinSnapshot'] != null
@@ -19,22 +39,10 @@ buildscript {
1939
maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
2040
maven { url "https://plugins.gradle.org/m2/" }
2141
}
22-
configurations.classpath {
23-
resolutionStrategy {
24-
eachDependency { DependencyResolveDetails details ->
25-
if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name != 'kotlin-native-gradle-plugin') {
26-
// fix version of all dependencies from org.jetbrains.kotlin group
27-
// even when other dependencies require other versions indirectly,
28-
// except kotlin-native, which has its own pre-release versioning
29-
details.useVersion kotlin_version
30-
}
31-
}
32-
}
33-
}
42+
3443
dependencies {
3544
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$artifactory_plugin_version"
3645
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
37-
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
3846
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
3947
classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFU_version"
4048
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
@@ -48,19 +56,26 @@ buildscript {
4856
}
4957

5058
allprojects {
59+
// the only place where HostManager could be instantiated
60+
project.ext.hostManager = new HostManager()
61+
}
62+
63+
allprojects {
64+
apply plugin: 'kotlinx-atomicfu'
65+
5166
def deployVersion = properties['DeployVersion']
5267
if (deployVersion != null) version = deployVersion
5368
if (useKotlinSnapshot) {
5469
kotlin_version = '1.2-SNAPSHOT'
5570
}
5671

57-
def name = it.name
72+
def projectName = it.name
5873
repositories {
5974
/*
6075
* google should be first in the repository list because some of the play services
6176
* transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
6277
*/
63-
if (name == "kotlinx-coroutines-play-services") {
78+
if (projectName == "kotlinx-coroutines-play-services") {
6479
google()
6580
}
6681
jcenter()
@@ -69,111 +84,72 @@ allprojects {
6984
maven { url "https://kotlin.bintray.com/kotlin-eap" }
7085
maven { url "https://kotlin.bintray.com/kotlinx" }
7186
}
72-
}
7387

88+
if (projectName == rootModule || projectName == coreModule) return
7489

75-
// Report Kotlin compiler version when building project
76-
println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
90+
// Add dependency to core source sets. Core is configured in kx-core/build.gradle
91+
evaluationDependsOn(":$coreModule")
92+
if (sourceless.contains(projectName)) return
7793

78-
// --------------- Configure sub-projects with Kotlin sources ---------------
94+
def platform = platformOf(it)
95+
apply from: rootProject.file("gradle/compile-${platform}.gradle")
7996

80-
def sourceless = ['site']
8197

82-
static def platformOf(project) {
83-
if (project.name.endsWith("-common")) return "common"
84-
if (project.name.endsWith("-js")) return "js"
85-
if (project.name.endsWith("-native")) return "native"
86-
return "jvm"
87-
}
98+
dependencies {
99+
// See comment below for rationale, it will be replaced with "project" dependency
100+
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
101+
compileOnly "org.jetbrains.kotlinx:atomicfu:$atomicFU_version"
88102

89-
static def platformLib(base, platform) {
90-
if (platform == "jvm") return base
91-
return "$base-$platform"
92-
}
103+
// the only way IDEA can resolve test classes
104+
testCompile project(":$coreModule").kotlin.targets.jvm.compilations.test.output.allOutputs
105+
}
93106

94-
subprojects {
95-
if (useKotlinSnapshot) {
96-
repositories {
97-
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
98-
}
107+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
108+
kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
109+
kotlinOptions.freeCompilerArgs += "-progressive"
110+
// Binary compatibility support
111+
kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
99112
}
113+
}
114+
115+
/*
116+
* Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
117+
* but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
118+
* for JVM-only projects.
119+
*
120+
* We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
121+
* to have out "project" dependency back.
122+
*/
123+
configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
100124
configurations.all {
101-
resolutionStrategy {
102-
eachDependency { DependencyResolveDetails details ->
103-
if (details.requested.group == 'org.jetbrains.kotlin') {
104-
details.useVersion kotlin_version
105-
}
106-
}
125+
resolutionStrategy.dependencySubstitution {
126+
substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
107127
}
108128
}
109129
}
110130

111-
configure(subprojects.findAll { !sourceless.contains(it.name) }) {
112-
def platform = platformOf(it)
113-
apply from: rootProject.file("gradle/compile-${platform}.gradle")
114-
}
115-
116-
// --------------- Configure sub-projects that are part of the library ---------------
117-
118-
def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator']
119-
120-
// Reconfigure source sets to avoid long "src/main/kotlin/fqn"
121-
configure(subprojects.findAll { !it.name.contains(sourceless) && it.name != "benchmarks" }) {
122-
def projectName = it.name
131+
// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
132+
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
123133
sourceSets {
124134
main.kotlin.srcDirs = ['src']
125135
test.kotlin.srcDirs = ['test']
126-
// todo: do we still need this workaround?
127-
if (!projectName.endsWith("-native")) {
128-
main.resources.srcDirs = ['resources']
129-
test.resources.srcDirs = ['test-resources']
130-
}
131-
}
132-
}
133-
134-
// configure atomicfu
135-
configure(subprojects.findAll { !internal.contains(it.name) }) {
136-
def platform = platformOf(it)
137-
apply from: rootProject.file("gradle/atomicfu-${platform}.gradle")
138-
}
139-
140-
// configure dependencies on core
141-
configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotlinx-coroutines-core-common'}) {
142-
def platform = platformOf(it)
143-
def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
136+
main.resources.srcDirs = ['resources']
137+
test.resources.srcDirs = ['test-resources']
144138

145-
if (it.name == coroutines_core) {
146-
dependencies {
147-
expectedBy project(':kotlinx-coroutines-core-common')
148-
}
149-
} else {
150-
dependencies {
151-
compile project(":$coroutines_core")
152-
//the only way IDEA can resolve test classes
153-
testCompile project(":$coroutines_core").sourceSets.test.output
154-
}
155139
}
156140
}
157141

158-
// --------------- Configure sub-projects that are published ---------------
159-
160-
def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'android-unit-tests']
161-
162-
def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/"
163-
def core_docs_file = "$projectDir/core/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
142+
def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
143+
def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
164144

165145
configure(subprojects.findAll { !unpublished.contains(it.name) }) {
166146
apply from: rootProject.file('gradle/dokka.gradle')
167147
apply from: rootProject.file('gradle/publish-bintray.gradle')
168148
}
169149

170150
configure(subprojects.findAll { !unpublished.contains(it.name) }) {
171-
def platform = platformOf(it)
172-
def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
173-
174-
if (it.name != coroutines_core) {
175-
dokka.dependsOn project(":$coroutines_core").dokka
176-
151+
if (it.name != coreModule) {
152+
dokka.dependsOn project(":$coreModule").dokka
177153
tasks.withType(dokka.getClass()) {
178154
externalDocumentationLink {
179155
url = new URL(core_docs_url)
@@ -182,27 +158,16 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
182158
}
183159
}
184160

185-
if (platform == "jvm") {
186-
dokkaJavadoc.dependsOn project(":$coroutines_core").dokka
187-
// dump declarations from main JVM module for binary-compatibility-validator
188-
compileKotlin {
189-
kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
190-
}
161+
if (platformOf(it) == "jvm") {
162+
dokkaJavadoc.dependsOn project(":$coreModule").dokka
191163
}
164+
}
192165

193166

194-
tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
195-
kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.Experimental",
196-
"-Xuse-experimental=kotlin.experimental.ExperimentalTypeInference",
197-
"-Xuse-experimental=kotlin.ExperimentalMultiplatform",
198-
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
199-
"-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi",
200-
"-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi",
201-
"-progressive"]
202-
}
203-
}
167+
// Report Kotlin compiler version when building project
168+
println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
204169

205-
// main deployment task
170+
// --------------- Configure sub-projects that are published ---------------
206171
task deploy(dependsOn: getTasksByName("bintrayUpload", true) + getTasksByName("publishNpm", true))
207172

208173
apply plugin: 'base'

common/README.md

-11
This file was deleted.

common/kotlinx-coroutines-core-common/README.md

-9
This file was deleted.

common/kotlinx-coroutines-core-common/build.gradle

-4
This file was deleted.

core/README.md

-11
This file was deleted.

0 commit comments

Comments
 (0)