Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 1 | <!--- TOC --> |
| 2 | |
| 3 | * [Compatibility](#compatibility) |
| 4 | * [Public API types](#public-api-types) |
| 5 | * [Experimental API](#experimental-api) |
Vsevolod Tolstopyatov | d57bfa2 | 2019-04-04 14:25:13 +0300 | [diff] [blame] | 6 | * [Flow preview API](#flow-preview-api) |
Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 7 | * [Obsolete API](#obsolete-api) |
| 8 | * [Internal API](#internal-api) |
| 9 | * [Stable API](#stable-api) |
| 10 | * [Deprecation cycle](#deprecation-cycle) |
| 11 | * [Using annotated API](#using-annotated-api) |
| 12 | * [Programmatically](#programmatically) |
| 13 | * [Gradle](#gradle) |
| 14 | * [Maven](#maven) |
| 15 | |
Roman Elizarov | 660c2d7 | 2020-02-14 13:18:37 +0300 | [diff] [blame] | 16 | <!--- END --> |
Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 17 | |
| 18 | ## Compatibility |
| 19 | This document describes the compatibility policy of `kotlinx.coroutines` library since version 1.0.0 and semantics of compatibility-specific annotations. |
| 20 | |
| 21 | |
| 22 | ## Public API types |
| 23 | `kotlinx.coroutines` public API comes in five flavours: stable, experimental, obsolete, internal and deprecated. |
| 24 | All public API except stable is marked with the corresponding annotation. |
| 25 | |
| 26 | ### Experimental API |
| 27 | Experimental API is marked with [@ExperimentalCoroutinesApi][ExperimentalCoroutinesApi] annotation. |
| 28 | API is marked experimental when its design has potential open questions which may eventually lead to |
| 29 | either semantics changes of the API or its deprecation. |
| 30 | |
| 31 | By default, most of the new API is marked as experimental and becomes stable in one of the next major releases if no new issues arise. |
| 32 | Otherwise, either semantics is fixed without changes in ABI or API goes through deprecation cycle. |
| 33 | |
| 34 | When using experimental API may be dangerous: |
| 35 | * You are writing a library which depends on `kotlinx.coroutines` and want to use experimental coroutines API in a stable library API. |
| 36 | It may lead to undesired consequences when end users of your library update their `kotlinx.coroutines` version where experimental API |
| 37 | has slightly different semantics. |
| 38 | * You want to build core infrastructure of the application around experimental API. |
| 39 | |
Vsevolod Tolstopyatov | d57bfa2 | 2019-04-04 14:25:13 +0300 | [diff] [blame] | 40 | ### Flow preview API |
| 41 | All [Flow]-related API is marked with [@FlowPreview][FlowPreview] annotation. |
| 42 | This annotation indicates that Flow API is in preview status. |
| 43 | We provide no compatibility guarantees between releases for preview features, including binary, source and semantics compatibility. |
| 44 | |
| 45 | When using preview API may be dangerous: |
| 46 | * You are writing a library/framework and want to use [Flow] API in a stable release or in a stable API. |
| 47 | * You want to use [Flow] in the core infrastructure of your application. |
| 48 | * You want to use [Flow] as "write-and-forget" solution and cannot afford additional maintenance cost when |
| 49 | it comes to `kotlinx.coroutines` updates. |
| 50 | |
| 51 | |
Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 52 | ### Obsolete API |
| 53 | Obsolete API is marked with [@ObsoleteCoroutinesApi][ObsoleteCoroutinesApi] annotation. |
| 54 | Obsolete API is similar to experimental, but already known to have serious design flaws and its potential replacement, |
| 55 | but replacement is not yet implemented. |
| 56 | |
| 57 | The semantics of this API won't be changed, but it will go through a deprecation cycle as soon as the replacement is ready. |
| 58 | |
| 59 | ### Internal API |
| 60 | Internal API is marked with [@InternalCoroutinesApi][InternalCoroutinesApi] or is part of `kotlinx.coroutines.internal` package. |
| 61 | This API has no guarantees on its stability, can and will be changed and/or removed in the future releases. |
| 62 | If you can't avoid using internal API, please report it to [issue tracker](https://github.com/Kotlin/kotlinx.coroutines/issues/new). |
| 63 | |
| 64 | ### Stable API |
| 65 | Stable API is guaranteed to preserve its ABI and documented semantics. If at some point unfixable design flaws will be discovered, |
| 66 | this API will go through a deprecation cycle and remain binary compatible as long as possible. |
| 67 | |
| 68 | ### Deprecation cycle |
| 69 | When some API is deprecated, it goes through multiple stages and there is at least one major release between stages. |
| 70 | * Feature is deprecated with compilation warning. Most of the time, proper replacement |
| 71 | (and corresponding `replaceWith` declaration) is provided to automatically migrate deprecated usages with a help of IntelliJ IDEA. |
| 72 | * Deprecation level is increased to `error` or `hidden`. It is no longer possible to compile new code against deprecated API, |
| 73 | though it is still present in the ABI. |
| 74 | * API is completely removed. While we give our best efforts not to do so and have no plans of removing any API, we still are leaving |
| 75 | this option in case of unforeseen problems such as security holes. |
| 76 | |
| 77 | ## Using annotated API |
| 78 | All API annotations are [kotlin.Experimental](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-experimental/index.html). |
| 79 | It is done in order to produce compilation warning about using experimental or obsolete API. |
| 80 | Warnings can be disabled either programmatically for a specific call site or globally for the whole module. |
| 81 | |
| 82 | ### Programmatically |
| 83 | For a specific call-site, warning can be disabled by using [UseExperimental](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-use-experimental/index.html) annotation: |
| 84 | ```kotlin |
| 85 | @UseExperimental(ExperimentalCoroutinesApi::class) // Disables warning about experimental coroutines API |
| 86 | fun experimentalApiUsage() { |
| 87 | someKotlinxCoroutinesExperimentalMethod() |
| 88 | } |
| 89 | ``` |
| 90 | |
| 91 | ### Gradle |
| 92 | For the Gradle project, a warning can be disabled by passing a compiler flag in your `build.gradle` file: |
| 93 | |
| 94 | ```groovy |
| 95 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all { |
| 96 | kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi"] |
| 97 | } |
| 98 | |
| 99 | ``` |
| 100 | |
| 101 | ### Maven |
| 102 | For the Maven project, a warning can be disabled by passing a compiler flag in your `pom.xml` file: |
| 103 | ```xml |
| 104 | <plugin> |
| 105 | <artifactId>kotlin-maven-plugin</artifactId> |
| 106 | <groupId>org.jetbrains.kotlin</groupId> |
| 107 | ... your configuration ... |
| 108 | <configuration> |
| 109 | <args> |
| 110 | <arg>-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi</arg> |
| 111 | </args> |
| 112 | </configuration> |
| 113 | </plugin> |
| 114 | ``` |
| 115 | |
| 116 | |
| 117 | <!--- MODULE kotlinx-coroutines-core --> |
Vsevolod Tolstopyatov | d57bfa2 | 2019-04-04 14:25:13 +0300 | [diff] [blame] | 118 | <!--- INDEX kotlinx.coroutines.flow --> |
Vsevolod Tolstopyatov | 167c44e | 2020-11-30 05:36:23 -0800 | [diff] [blame] | 119 | |
Vsevolod Tolstopyatov | d57bfa2 | 2019-04-04 14:25:13 +0300 | [diff] [blame] | 120 | [Flow]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html |
Vsevolod Tolstopyatov | 167c44e | 2020-11-30 05:36:23 -0800 | [diff] [blame] | 121 | |
Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 122 | <!--- INDEX kotlinx.coroutines --> |
Vsevolod Tolstopyatov | 167c44e | 2020-11-30 05:36:23 -0800 | [diff] [blame] | 123 | |
Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 124 | [ExperimentalCoroutinesApi]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-experimental-coroutines-api/index.html |
Vsevolod Tolstopyatov | d57bfa2 | 2019-04-04 14:25:13 +0300 | [diff] [blame] | 125 | [FlowPreview]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-flow-preview/index.html |
Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 126 | [ObsoleteCoroutinesApi]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-obsolete-coroutines-api/index.html |
| 127 | [InternalCoroutinesApi]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-internal-coroutines-api/index.html |
Vsevolod Tolstopyatov | 167c44e | 2020-11-30 05:36:23 -0800 | [diff] [blame] | 128 | |
Vsevolod Tolstopyatov | 4764e98 | 2019-02-04 12:39:34 +0300 | [diff] [blame] | 129 | <!--- END --> |