use a kotlin multiplatform lib in another kotlin multiplatfor lib

有些话、适合烂在心里 提交于 2021-01-05 07:09:33

问题


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 commonTest by getting {
            dependencies {

            implementation(kotlin("test-common"))
            implementation(kotlin("test-annotations-common"))
        }
    }
    val jvmMain by getting {
        dependencies {

           
            implementation("groupId:L1-jvm:1.0-SNAPSHOT")
        }
    }
    val jvmTest by getting {
        dependencies {

            implementation(kotlin("test-junit"))
        }
    }
    val jsMain by getting {
        dependencies {
            implementation("groupId:L1-js:1.0-SNAPSHOT")
        }
    }
    val jsTest by getting {
        dependencies {

            implementation(kotlin("test-js"))
        }
    }
}

}

来源:https://stackoverflow.com/questions/65233929/use-a-kotlin-multiplatform-lib-in-another-kotlin-multiplatfor-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!