Skip to content

Commit 5a78418

Browse files
authored
update: recommendations on platform-specific kotlinx libraries removed (#4682)
1 parent 683a919 commit 5a78418

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

docs/topics/gradle/gradle-configure-project.md

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,8 @@ To add a dependency on a library, set the dependency of the required [type](#dep
733733
```kotlin
734734
kotlin {
735735
sourceSets {
736-
val commonMain by getting {
737-
dependencies {
738-
implementation("com.example:my-library:1.0")
739-
}
736+
commonMain.dependencies {
737+
implementation("com.example:my-library:1.0")
740738
}
741739
}
742740
}
@@ -977,10 +975,8 @@ Kotlin/Native targets do not require additional test dependencies, and the `kotl
977975
```kotlin
978976
kotlin {
979977
sourceSets {
980-
val commonTest by getting {
981-
dependencies {
982-
implementation(kotlin("test")) // This brings all the platform dependencies automatically
983-
}
978+
commonTest.dependencies {
979+
implementation(kotlin("test")) // This brings all the platform dependencies automatically
984980
}
985981
}
986982
}
@@ -1032,10 +1028,8 @@ kotlin {
10321028
}
10331029
}
10341030
sourceSets {
1035-
val commonTest by getting {
1036-
dependencies {
1037-
implementation(kotlin("test"))
1038-
}
1031+
commonTest.dependencies {
1032+
implementation(kotlin("test"))
10391033
}
10401034
}
10411035
}
@@ -1108,24 +1102,21 @@ kotlin.test.infer.jvm.variant=false
11081102
11091103
If you have used a variant of `kotlin("test")` in your build script explicitly and your project build stopped working with
11101104
a compatibility conflict,
1111-
see [this issue in the Compatibility Guide](compatibility-guide-15.md#do-not-mix-several-jvm-variants-of-kotlin-test-in-a-single-project).
1105+
see [this issue in the Compatibility guide](compatibility-guide-15.md#do-not-mix-several-jvm-variants-of-kotlin-test-in-a-single-project).
11121106
11131107
### Set a dependency on a kotlinx library
11141108
1115-
If you use a [`kotlinx` library](https://github.com/Kotlin/kotlinx.coroutines) and need a platform-specific dependency,
1116-
you can use platform-specific variants of libraries with suffixes such as `-jvm` or `-js`, for example,
1117-
`kotlinx-coroutines-core-jvm`. You can also use the library's base artifact name instead – `kotlinx-coroutines-core`.
1109+
If you use a multiplatform library and need to depend on the shared code, set the dependency only once in the shared
1110+
source set. Use the library's base artifact name, such as `kotlinx-coroutines-core` or `ktor-client-core`:
11181111
11191112
<tabs group="build-script">
11201113
<tab title="Kotlin" group-key="kotlin">
11211114
11221115
```kotlin
11231116
kotlin {
11241117
sourceSets {
1125-
val jvmMain by getting {
1126-
dependencies {
1127-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%")
1128-
}
1118+
commonMain.dependencies {
1119+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
11291120
}
11301121
}
11311122
}
@@ -1137,9 +1128,9 @@ kotlin {
11371128
```groovy
11381129
kotlin {
11391130
sourceSets {
1140-
jvmMain {
1131+
commonMain {
11411132
dependencies {
1142-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%'
1133+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
11431134
}
11441135
}
11451136
}
@@ -1149,19 +1140,17 @@ kotlin {
11491140
</tab>
11501141
</tabs>
11511142
1152-
If you use a multiplatform library and need to depend on the shared code, set the dependency only once, in the shared
1153-
source set. Use the library's base artifact name, such as `kotlinx-coroutines-core` or `ktor-client-core`.
1143+
If you need a kotlinx library for a platform-specific dependency, you can still use the library's base artifact name in
1144+
the corresponding platform source set:
11541145
11551146
<tabs group="build-script">
11561147
<tab title="Kotlin" group-key="kotlin">
11571148
11581149
```kotlin
11591150
kotlin {
11601151
sourceSets {
1161-
val commonMain by getting {
1162-
dependencies {
1163-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
1164-
}
1152+
jvmMain.dependencies {
1153+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
11651154
}
11661155
}
11671156
}
@@ -1173,7 +1162,7 @@ kotlin {
11731162
```groovy
11741163
kotlin {
11751164
sourceSets {
1176-
commonMain {
1165+
jvmMain {
11771166
dependencies {
11781167
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
11791168
}

docs/topics/multiplatform/multiplatform-add-dependencies.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ kotlin {
9292
### kotlinx libraries
9393

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

9797
<tabs group="build-script">
9898
<tab title="Kotlin" group-key="kotlin">
@@ -125,9 +125,8 @@ kotlin {
125125
</tab>
126126
</tabs>
127127

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

132131
<tabs group="build-script">
133132
<tab title="Kotlin" group-key="kotlin">
@@ -136,7 +135,7 @@ example, `kotlinx-coroutines-core-jvm`.
136135
kotlin {
137136
sourceSets {
138137
jvmMain.dependencies {
139-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%")
138+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
140139
}
141140
}
142141
}
@@ -150,7 +149,7 @@ kotlin {
150149
sourceSets {
151150
jvmMain {
152151
dependencies {
153-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%'
152+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
154153
}
155154
}
156155
}

docs/topics/scripting/custom-script-deps-tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ In this tutorial, this includes support for the `@Repository` and `@DependsOn` a
133133
implementation 'org.jetbrains.kotlin:kotlin-scripting-dependencies'
134134
implementation 'org.jetbrains.kotlin:kotlin-scripting-dependencies-maven'
135135
// coroutines dependency is required for this particular definition
136-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:%coroutinesVersion%'
136+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%'
137137
138138
}
139139
```

0 commit comments

Comments
 (0)