Skip to content

Commit

Permalink
update: recommendations on platform-specific kotlinx libraries removed (
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-pavlov authored Feb 21, 2025
1 parent 683a919 commit 5a78418
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
47 changes: 18 additions & 29 deletions docs/topics/gradle/gradle-configure-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,8 @@ To add a dependency on a library, set the dependency of the required [type](#dep
```kotlin
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.example:my-library:1.0")
}
commonMain.dependencies {
implementation("com.example:my-library:1.0")
}
}
}
Expand Down Expand Up @@ -977,10 +975,8 @@ Kotlin/Native targets do not require additional test dependencies, and the `kotl
```kotlin
kotlin {
sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test")) // This brings all the platform dependencies automatically
}
commonTest.dependencies {
implementation(kotlin("test")) // This brings all the platform dependencies automatically
}
}
}
Expand Down Expand Up @@ -1032,10 +1028,8 @@ kotlin {
}
}
sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
commonTest.dependencies {
implementation(kotlin("test"))
}
}
}
Expand Down Expand Up @@ -1108,24 +1102,21 @@ kotlin.test.infer.jvm.variant=false
If you have used a variant of `kotlin("test")` in your build script explicitly and your project build stopped working with
a compatibility conflict,
see [this issue in the Compatibility Guide](compatibility-guide-15.md#do-not-mix-several-jvm-variants-of-kotlin-test-in-a-single-project).
see [this issue in the Compatibility guide](compatibility-guide-15.md#do-not-mix-several-jvm-variants-of-kotlin-test-in-a-single-project).
### Set a dependency on a kotlinx library
If you use a [`kotlinx` library](https://github.com/Kotlin/kotlinx.coroutines) and need a platform-specific dependency,
you can use platform-specific variants of libraries with suffixes such as `-jvm` or `-js`, for example,
`kotlinx-coroutines-core-jvm`. You can also use the library's base artifact name instead – `kotlinx-coroutines-core`.
If you use a multiplatform library and need to depend on the shared code, set the dependency only once in the shared
source set. Use the library's base artifact name, such as `kotlinx-coroutines-core` or `ktor-client-core`:
<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">
```kotlin
kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%")
}
commonMain.dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
}
}
}
Expand All @@ -1137,9 +1128,9 @@ kotlin {
```groovy
kotlin {
sourceSets {
jvmMain {
commonMain {
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
}
}
}
Expand All @@ -1149,19 +1140,17 @@ kotlin {
</tab>
</tabs>
If you use a multiplatform library and need to depend on the shared code, set the dependency only once, in the shared
source set. Use the library's base artifact name, such as `kotlinx-coroutines-core` or `ktor-client-core`.
If you need a kotlinx library for a platform-specific dependency, you can still use the library's base artifact name in
the corresponding platform source set:
<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">
```kotlin
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
}
jvmMain.dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
}
}
}
Expand All @@ -1173,7 +1162,7 @@ kotlin {
```groovy
kotlin {
sourceSets {
commonMain {
jvmMain {
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
}
Expand Down
11 changes: 5 additions & 6 deletions docs/topics/multiplatform/multiplatform-add-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ kotlin {
### kotlinx libraries

If you use a multiplatform library and need to [depend on the shared code](#library-shared-for-all-source-sets), set the
dependency only once in the shared source set. Use the library base artifact name, such as `kotlinx-coroutines-core`.
dependency only once in the shared source set. Use the library base artifact name, such as `kotlinx-coroutines-core`:

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">
Expand Down Expand Up @@ -125,9 +125,8 @@ kotlin {
</tab>
</tabs>

If you use a kotlinx library and need a [platform-specific dependency](#library-used-in-specific-source-sets), you can
use platform-specific variants of libraries with suffixes such as `-jvm` or `-js`, for
example, `kotlinx-coroutines-core-jvm`.
If you need a kotlinx library for a [platform-specific dependency](#library-used-in-specific-source-sets), you can
still use library's base artifact name in the corresponding platform source set:

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">
Expand All @@ -136,7 +135,7 @@ example, `kotlinx-coroutines-core-jvm`.
kotlin {
sourceSets {
jvmMain.dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
}
}
}
Expand All @@ -150,7 +149,7 @@ kotlin {
sourceSets {
jvmMain {
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/scripting/custom-script-deps-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ In this tutorial, this includes support for the `@Repository` and `@DependsOn` a
implementation 'org.jetbrains.kotlin:kotlin-scripting-dependencies'
implementation 'org.jetbrains.kotlin:kotlin-scripting-dependencies-maven'
// coroutines dependency is required for this particular definition
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
}
```
Expand Down

0 comments on commit 5a78418

Please sign in to comment.