Build project using JDK 11 (#1733)

* Support build on both JDK 1.8 & 11, check for publishing under JDK 11
* Up the Robolectric version to support JDK11.
  According to https://github.com/robolectric/robolectric/issues/4085, by 4.0.2
it should support JDK11.
  Tests do pass after setting the version to 4.0.2, but they fail for every version released after that up to 4.3.1.
  It is unclear what causes this. I commit this to check how it works on the build agents, as some comments in the issue imply that on MacOS this version, too, does not work with JDK11.
* Fix fully qualified names in stacktraces in tests:
  - With move to JDK11, the `park` method changed its fully qualified name.
* Add new sanitazing to verification of stacktraces:
  - Now stacktraces have additional substrings, separated by a slash:
    java-base/java.util.lang
  - They are stripped away.
  - Also, the placement of tabs has changed, and so the tabs are also completely removed.
* Refactor `verifyStackTrace`
  - It used to wrap the only loop where something happened in two other loops that did nothing. Now, only the innermost loop is left.
* Use a separate JavaFx dependency.
* Improve error handling for JavaFX initialization
  - Now, the JavaFX initialization may fail with an exception in case something went wrong.
  - The driver for this change was that the initialization started hanging in headless environments with transition to JDK 11.
  - Before, the initialization logic had a flaw. If a call to one API
failed, another API would be attempted. However, this approach is
problematic: if the first call failed with an exception for some
reason, it would leave JavaFX in a broken state where a flag would
imply that the system is being initialized. Subsequent calls would
then proceed to wait forever for the initialization to complete.
  - Now, exceptions are checked more carefully, ensuring that we only
fall back to the internal API in case the public one is unavailable
and not failed for some valid reason. This differentiation also
allows to more boldly rethrow exceptions upwards, being more or
less confident that these are relevant to the user.
* Additionally test JavaFX integration with JDK8

Co-authored-by: Dmitry Khalanskiy <dmitry.khalanskiy@jetbrains.com>
Co-authored-by: Roman Elizarov <elizarov@gmail.com>
11 files changed
tree: 61a95dd899a27150dc64fe715752b6ab8dac0158
  1. benchmarks/
  2. docs/
  3. gradle/
  4. integration/
  5. js/
  6. kotlinx-coroutines-bom/
  7. kotlinx-coroutines-core/
  8. kotlinx-coroutines-debug/
  9. kotlinx-coroutines-test/
  10. license/
  11. publication-validator/
  12. reactive/
  13. site/
  14. stdlib-stubs/
  15. ui/
  16. .gitignore
  17. build.gradle
  18. bump-version.sh
  19. CHANGES.md
  20. CODE_OF_CONDUCT.md
  21. coroutines-guide.md
  22. gradle.properties
  23. gradlew
  24. gradlew.bat
  25. LICENSE.txt
  26. README.md
  27. RELEASE.md
  28. settings.gradle
README.md

kotlinx.coroutines

official JetBrains project GitHub license Download

Library support for Kotlin coroutines with multiplatform support. This is a companion version for Kotlin 1.3.61 release.

suspend fun main() = coroutineScope {
    launch { 
       delay(1000)
       println("Kotlin Coroutines World!") 
    }
    println("Hello")
}

Play with coroutines online here

Modules

Documentation

Using in your projects

The libraries are published to kotlinx bintray repository, linked to JCenter and pushed to Maven Central.

Maven

Add dependencies (you can also add other modules that you need):

<dependency>
    <groupId>org.jetbrains.kotlinx</groupId>
    <artifactId>kotlinx-coroutines-core</artifactId>
    <version>1.3.3</version>
</dependency>

And make sure that you use the latest Kotlin version:

<properties>
    <kotlin.version>1.3.61</kotlin.version>
</properties>

Gradle

Add dependencies (you can also add other modules that you need):

dependencies {
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
}

And make sure that you use the latest Kotlin version:

buildscript {
    ext.kotlin_version = '1.3.61'
}

Make sure that you have either jcenter() or mavenCentral() in the list of repositories:

repository {
    jcenter()
}

Gradle Kotlin DSL

Add dependencies (you can also add other modules that you need):

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
}

And make sure that you use the latest Kotlin version:

plugins {
    kotlin("jvm") version "1.3.61"
}

Make sure that you have either jcenter() or mavenCentral() in the list of repositories.

Multiplatform

Core modules of kotlinx.coroutines are also available for Kotlin/JS and Kotlin/Native. In common code that should get compiled for different platforms, add dependency to
kotlinx-coroutines-core-common
(follow the link to get the dependency declaration snippet).

Android

Add kotlinx-coroutines-android module as dependency when using kotlinx.coroutines on Android:

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'

This gives you access to Android Dispatchers.Main coroutine dispatcher and also makes sure that in case of crashed coroutine with unhandled exception this exception is logged before crashing Android application, similarly to the way uncaught exceptions in threads are handled by Android runtime.

R8 and ProGuard

For R8 no actions required, it will take obfuscation rules from the jar.

For Proguard you need to add options from coroutines.pro to your rules manually.

R8 is a replacement for ProGuard in Android ecosystem, it is enabled by default since Android gradle plugin 3.4.0 (3.3.0-beta also had it enabled).

JS

Kotlin/JS version of kotlinx.coroutines is published as kotlinx-coroutines-core-js (follow the link to get the dependency declaration snippet).

You can also use kotlinx-coroutines-core package via NPM.

Native

Kotlin/Native version of kotlinx.coroutines is published as kotlinx-coroutines-core-native (follow the link to get the dependency declaration snippet).

Only single-threaded code (JS-style) on Kotlin/Native is currently supported. Kotlin/Native supports only Gradle version 4.10 and you need to enable Gradle metadata in your settings.gradle file:

enableFeaturePreview('GRADLE_METADATA')

Since Kotlin/Native does not generally provide binary compatibility between versions, you should use the same version of Kotlin/Native compiler as was used to build kotlinx.coroutines.

Building

This library is built with Gradle. To build it, use ./gradlew build. You can import this project into IDEA, but you have to delegate build actions to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner)

Requirements

  • JDK >= 11 referred to by the JAVA_HOME environment variable.
  • JDK 1.6 referred to by the JDK_16 environment variable. It is okay to have JDK_16 pointing to JAVA_HOME for external contributions.
  • JDK 1.8 referred to by the JDK_18 environment variable. Only used by nightly stress-tests. It is okay to have JDK_16 pointing to JAVA_HOME for external contributions.

Contributions and releases

All development (both new features and bug fixes) is performed in develop branch. This way master sources always contain sources of the most recently released version. Please send PRs with bug fixes to develop branch. Fixes to documentation in markdown files are an exception to this rule. They are updated directly in master.

The develop branch is pushed to master during release.

  • Full release procedure checklist is here.
  • Steps for contributing new integration modules are explained here.
  • Use Knit for updates to documentation:
    • In project root directory run ./gradlew knit.
    • Commit updated documents and examples together with other changes.
  • Use Binary Compatibility Validator for updates to public API:
    • In project root directory run ./gradlew apiDump.
    • Commit updated API index together with other changes.