添加依赖项

    1. kotlin {
    2. sourceSets {
    3. val commonMain by getting {
    4. dependencies {
    5. implementation("com.example:my-library:1.0")
    6. }
    7. }
    8. }

    Alternatively, you can .

    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 change the default behavior.

    The is available for multiplatform tests. When you create a multiplatform project, 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.

    1. kotlin {
    2. sourceSets {
    3. val jvmMain by getting {
    4. dependencies {
    5. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.4.2")
    6. }
    7. }
    8. }

    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.

    1. kotlin {
    2. sourceSets {
    3. val commonMain by getting {
    4. dependencies {
    5. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
    6. }
    7. }
    8. }