Skip to content

Migration to new multiplatorm plugin #947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GlobalScope.launch {

## Modules

* [common](common/README.md) — common coroutines across all platforms:
* [core](kotlinx-coroutines-core/README.md) — common coroutines across all platforms:
* `launch` and `async` coroutine builders;
* `Job` and `Deferred` light-weight future with cancellation support;
* `MainScope` for Android and UI applications.
Expand All @@ -29,15 +29,16 @@ GlobalScope.launch {
* `coroutineScope` and `supervisorScope` scope builders;
* `SupervisorJob` and `CoroutineExceptionHandler` for supervision of coroutines hierarchies;
* `select` expression support and more.
* [core](core/README.md) — Kotlin/JVM implementation of common coroutines with additional features:
* [core/jvm](kotlinx-coroutines-core/jvm/) — additional core features available on Kotlin/JVM:
* `Dispatchers.IO` dispatcher for blocking coroutines;
* `Executor.asCoroutineDispatcher()` extension, custom thread pools, and more.
* [test](core/README.md) — test utilities for coroutines
* [core/js](kotlinx-coroutines-core/js/) — additional core features available on Kotlin/JS:
* Integration with `Promise`;
* Integration with `Window`.
* [test](kotlinx-coroutines-test/README.md) — test utilities for coroutines
* `Dispatchers.setMain` to override `Dispatchers.Main` in tests.
* [debug](core/README.md) — debug utilities for coroutines.
* [debug](kotlinx-coroutines-debug/README.md) — debug utilities for coroutines.
* `DebugProbes` API to probe, keep track of, print and dump active coroutines.
* [js](js/README.md) — Kotlin/JS implementation of common coroutines with `Promise` support.
* [native](native/README.md) — Kotlin/Native implementation of common coroutines with `runBlocking` single-threaded event loop.
* [reactive](reactive/README.md) — modules that provide builders and iteration support for various reactive streams libraries:
* Reactive Streams, RxJava 2.x, and Project Reactor.
* [ui](ui/README.md) — modules that provide coroutine dispatchers for various single-threaded UI libraries:
Expand Down
8 changes: 6 additions & 2 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ repositories {

jmh.jmhVersion = '1.21'

jmh {
duplicateClassesStrategy DuplicatesStrategy.INCLUDE
}

jmhJar {
baseName 'benchmarks'
classifier = null
Expand All @@ -20,8 +24,8 @@ jmhJar {
}

dependencies {
compile "org.openjdk.jmh:jmh-core:1.21"
compile 'com.typesafe.akka:akka-actor_2.12:2.5.0'
compile project(':kotlinx-coroutines-core-common')
compile project(':kotlinx-coroutines-core')
compile "org.openjdk.jmh:jmh-core:1.21"
}

4 changes: 2 additions & 2 deletions binary-compatibility-validator/resources/api.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
#

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

packages.internal=kotlinx.coroutines.internal
3 changes: 2 additions & 1 deletion binary-compatibility-validator/test/PublicApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class PublicApiTest(
it matches regex
&& !it.endsWith("-sources.jar")
&& !it.endsWith("-javadoc.jar")
&& !it.endsWith("-tests.jar")} }
&& !it.endsWith("-tests.jar")}
&& !it.name.contains("-metadata-")}
return files.singleOrNull() ?: throw Exception("No single file matching $regex in $libsDir:\n${files.joinToString("\n")}")
}
}
187 changes: 76 additions & 111 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
/*
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
import org.jetbrains.kotlin.konan.target.HostManager

apply from: rootProject.file("gradle/experimental.gradle")

def rootModule = "kotlinx.coroutines"
def coreModule = "kotlinx-coroutines-core"
// Not applicable for Kotlin plugin
def sourceless = ['kotlinx.coroutines', 'site']
def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator']
// Not published
def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'android-unit-tests']

static def platformOf(project) {
def name = project.name
if (name.endsWith("-js")) return "js"
if (name.endsWith("-common") || name.endsWith("-native")) {
throw IllegalStateException("$name platform is not supported")
}
return "jvm"
}

buildscript {
ext.useKotlinSnapshot = rootProject.properties['kotlinSnapshot'] != null
Expand All @@ -19,22 +39,10 @@ buildscript {
maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
maven { url "https://plugins.gradle.org/m2/" }
}
configurations.classpath {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name != 'kotlin-native-gradle-plugin') {
// fix version of all dependencies from org.jetbrains.kotlin group
// even when other dependencies require other versions indirectly,
// except kotlin-native, which has its own pre-release versioning
details.useVersion kotlin_version
}
}
}
}

dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$artifactory_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFU_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
Expand All @@ -48,19 +56,26 @@ buildscript {
}

allprojects {
// the only place where HostManager could be instantiated
project.ext.hostManager = new HostManager()
}

allprojects {
apply plugin: 'kotlinx-atomicfu'

def deployVersion = properties['DeployVersion']
if (deployVersion != null) version = deployVersion
if (useKotlinSnapshot) {
kotlin_version = '1.2-SNAPSHOT'
}

def name = it.name
def projectName = it.name
repositories {
/*
* google should be first in the repository list because some of the play services
* transitive dependencies was removed from jcenter, thus breaking gradle dependency resolution
*/
if (name == "kotlinx-coroutines-play-services") {
if (projectName == "kotlinx-coroutines-play-services") {
google()
}
jcenter()
Expand All @@ -69,111 +84,72 @@ allprojects {
maven { url "https://kotlin.bintray.com/kotlin-eap" }
maven { url "https://kotlin.bintray.com/kotlinx" }
}
}

if (projectName == rootModule || projectName == coreModule) return

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

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

def sourceless = ['site']

static def platformOf(project) {
if (project.name.endsWith("-common")) return "common"
if (project.name.endsWith("-js")) return "js"
if (project.name.endsWith("-native")) return "native"
return "jvm"
}
dependencies {
// See comment below for rationale, it will be replaced with "project" dependency
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
compileOnly "org.jetbrains.kotlinx:atomicfu:$atomicFU_version"

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

subprojects {
if (useKotlinSnapshot) {
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
kotlinOptions.freeCompilerArgs += experimentalAnnotations.collect { "-Xuse-experimental=" + it }
kotlinOptions.freeCompilerArgs += "-progressive"
// Binary compatibility support
kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
}
}

/*
* Hack to trick nmpp plugin: we are renaming artifacts in order to provide backward compatibility for dependencies,
* but publishing plugin does not re-read artifact names for kotlin-jvm projects, so renaming is not applied in pom files
* for JVM-only projects.
*
* We artificially replace "project" dependency with "module" one to have proper names in pom files, but then substitute it
* to have out "project" dependency back.
*/
configure(subprojects.findAll { it.name != coreModule && it.name != rootModule }) {
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.jetbrains.kotlin') {
details.useVersion kotlin_version
}
}
resolutionStrategy.dependencySubstitution {
substitute module("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version") with project(':kotlinx-coroutines-core')
}
}
}

configure(subprojects.findAll { !sourceless.contains(it.name) }) {
def platform = platformOf(it)
apply from: rootProject.file("gradle/compile-${platform}.gradle")
}

// --------------- Configure sub-projects that are part of the library ---------------

def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'stdlib-stubs', 'binary-compatibility-validator']

// Reconfigure source sets to avoid long "src/main/kotlin/fqn"
configure(subprojects.findAll { !it.name.contains(sourceless) && it.name != "benchmarks" }) {
def projectName = it.name
// Redefine source sets because we are not using 'kotlin/main/fqn' folder convention
configure(subprojects.findAll { !sourceless.contains(it.name) && it.name != "benchmarks" && it.name != coreModule }) {
sourceSets {
main.kotlin.srcDirs = ['src']
test.kotlin.srcDirs = ['test']
// todo: do we still need this workaround?
if (!projectName.endsWith("-native")) {
main.resources.srcDirs = ['resources']
test.resources.srcDirs = ['test-resources']
}
}
}

// configure atomicfu
configure(subprojects.findAll { !internal.contains(it.name) }) {
def platform = platformOf(it)
apply from: rootProject.file("gradle/atomicfu-${platform}.gradle")
}

// configure dependencies on core
configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotlinx-coroutines-core-common'}) {
def platform = platformOf(it)
def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
main.resources.srcDirs = ['resources']
test.resources.srcDirs = ['test-resources']

if (it.name == coroutines_core) {
dependencies {
expectedBy project(':kotlinx-coroutines-core-common')
}
} else {
dependencies {
compile project(":$coroutines_core")
//the only way IDEA can resolve test classes
testCompile project(":$coroutines_core").sourceSets.test.output
}
}
}

// --------------- Configure sub-projects that are published ---------------

def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'android-unit-tests']

def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/"
def core_docs_file = "$projectDir/core/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/$coreModule/"
def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"

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

configure(subprojects.findAll { !unpublished.contains(it.name) }) {
def platform = platformOf(it)
def coroutines_core = platformLib("kotlinx-coroutines-core", platform)

if (it.name != coroutines_core) {
dokka.dependsOn project(":$coroutines_core").dokka

if (it.name != coreModule) {
dokka.dependsOn project(":$coreModule").dokka
tasks.withType(dokka.getClass()) {
externalDocumentationLink {
url = new URL(core_docs_url)
Expand All @@ -182,27 +158,16 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
}
}

if (platform == "jvm") {
dokkaJavadoc.dependsOn project(":$coroutines_core").dokka
// dump declarations from main JVM module for binary-compatibility-validator
compileKotlin {
kotlinOptions.freeCompilerArgs += ["-Xdump-declarations-to=${buildDir}/visibilities.json"]
}
if (platformOf(it) == "jvm") {
dokkaJavadoc.dependsOn project(":$coreModule").dokka
}
}


tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.Experimental",
"-Xuse-experimental=kotlin.experimental.ExperimentalTypeInference",
"-Xuse-experimental=kotlin.ExperimentalMultiplatform",
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi",
"-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi",
"-progressive"]
}
}
// Report Kotlin compiler version when building project
println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")

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

apply plugin: 'base'
Expand Down
11 changes: 0 additions & 11 deletions common/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions common/kotlinx-coroutines-core-common/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions common/kotlinx-coroutines-core-common/build.gradle

This file was deleted.

11 changes: 0 additions & 11 deletions core/README.md

This file was deleted.

Loading