Add dependencies
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.example:my-library:1.0")
}
}
}
Alternatively, you can set dependencies at the top level.
A dependency on a standard library (stdlib
) in each source set is added automatically. The version of the standard library is the same as the version of the kotlin-multiplatform
plugin.
Learn how to .
The kotlin.test
API is available for multiplatform tests. When you , the Project Wizard automatically adds test dependencies to common and platform-specific source sets.
If you use a kotlinx library 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 base artifact name instead – kotlinx-coroutines-core
.
kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.2")
}
}
}
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 base artifact name, such as kotlinx-coroutines-core
or ktor-client-core
.
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
}
}
}