Use a kotlin multiplatform lib in another kotlin multiplatfor lib

kotlin 1.4.21 here

I have create a multiplatform kotlin librarie (L1)using intellij in gradle, who build in JS and JVM.

I want to reuse this lib in another multiplatform kotlin lib L2 How can I do it?

I have issue with importing the “common” part of L1 in the common target of L2, (the eror are a lot of Unresolved reference ), basicaly the common target of L2 cannot find the implementation contained in L1.

I have only this issue with the common target, the js and jvm work fine.

the gradle of L1, the lib to be reused

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        testRuns["test"].executionTask.configure {
            useJUnit()
        }
    }
    js(LEGACY) {
        browser {
            testTask {
                useKarma {
                    useChromeHeadless()
                    webpackConfig.cssSupport.enabled = true
                }
            }
        }
    }
    
    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
            }
        }
        val jsMain by getting
        val jsTest by getting {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
    }
}

the gradle of L2,the lib who reuse L1:

sourceSets {
    val commonMain by getting {
        dependencies {
         
            implementation("groupId:L1:1.0-SNAPSHOT")
        }
    }
    val jvmMain by getting {
        dependencies {
            implementation("groupId:L1-jvm:1.0-SNAPSHOT")
        }
    }
    val jsMain by getting {
        dependencies {
            implementation("groupId:L1-js:1.0-SNAPSHOT")
        }
    }
}

Did you enable the GRADLE_METADATA feature preview?

settings.gradle.kts:

enableFeaturePreview("GRADLE_METADATA")

Also there should be no need to include the dependencies for jvmMain and jsMain, in a MPP project they should be picked up automatically.

1 Like