Skip to content

Commit

Permalink
update: adding dependencies on multiplatform libs (JetBrains#3055)
Browse files Browse the repository at this point in the history
* KT-49393 and minor fixes
  • Loading branch information
danil-pavlov authored Jul 11, 2022
1 parent e84d0e8 commit c7c3477
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions docs/topics/multiplatform/multiplatform-add-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.example:my-library:1.0")
implementation("com.example:my-library:1.0") // library shared for all source sets
}
}
}
Expand Down Expand Up @@ -153,16 +153,26 @@ Check out this [community-maintained list of Kotlin Multiplatform libraries](htt
If you want to use a library from all source sets, you can add it only to the common source set. The Kotlin
Multiplatform Mobile plugin will automatically add the corresponding parts to any other source sets.

> You cannot set dependencies on platform-specific libraries in the common source set.
>
{type="warning"}

<tabs group="build-script">
<tab title="Kotlin" group-key="kotlin">

```kotlin
kotlin {
sourceSets["commonMain"].dependencies {
implementation("io.ktor:ktor-client-core:%ktorVersion%")
}
sourceSets["androidMain"].dependencies {
//dependency to platform part of kotlinx.coroutines will be added automatically
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:%ktorVersion%")
}
}
val androidMain by getting {
dependencies {
// dependency to a platform part of ktor-client will be added automatically
}
}
}
}
```
Expand All @@ -180,7 +190,7 @@ kotlin {
}
androidMain {
dependencies {
//dependency to platform part of kotlinx.coroutines will be added automatically
// dependency to platform part of ktor-client will be added automatically
}
}
}
Expand All @@ -204,15 +214,22 @@ specified library declarations will then be available only in those source sets.

```kotlin
kotlin {
sourceSets["commonMain"].dependencies {
//kotlinx.coroutines will be available in all source sets
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
}
sourceSets["androidMain"].dependencies {
}
sourceSets["iosX64Main"].dependencies {
//SQLDelight will be available only in the iOS source set, but not in Android or common
implementation("com.squareup.sqldelight:native-driver:%sqlDelightVersion%")
sourceSets {
val commonMain by getting {
dependencies {
// kotlinx.coroutines will be available in all source sets
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:%coroutinesVersion%")
}
}
val androidMain by getting {
dependencies {}
}
val iosMain by getting {
dependencies {
// SQLDelight will be available only in the iOS source set, but not in Android or common
implementation("com.squareup.sqldelight:native-driver:%sqlDelightVersion%")
}
}
}
}
```
Expand Down Expand Up @@ -264,11 +281,17 @@ other source sets will get their versions automatically.

```kotlin
kotlin {
sourceSets["commonMain"].dependencies {
implementation(project(":some-other-multiplatform-module"))
}
sourceSets["androidMain"].dependencies {
//platform part of :some-other-multiplatform-module will be added automatically
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":some-other-multiplatform-module"))
}
}
val androidMain by getting {
dependencies {
// platform part of :some-other-multiplatform-module will be added automatically
}
}
}
}
```
Expand All @@ -286,7 +309,7 @@ kotlin {
}
androidMain {
dependencies {
//platform part of :some-other-multiplatform-module will be added automatically
// platform part of :some-other-multiplatform-module will be added automatically
}
}
}
Expand Down

0 comments on commit c7c3477

Please sign in to comment.