Given a Kotlin Multiplatform project (v1.4.21) wit...
# javascript
j
Given a Kotlin Multiplatform project (v1.4.21) with the following layout: --------------------------------------------
Project
SubProjectA
_Dependencies_:
SubProjectB
_Dependencies_:
SubProjectA
SubProjectC
_Dependencies_:
SubProjectB
-------------------------------------------- ...I am trying to create a Javascript build of SubProjectC that can be used by a Typescript-based backend service. The goal is to be able to add the JS build of SubProjectC via
yarn
(or
npm
). I am able to create a JS build by adding the following in the
build.gradle.kts
of all subprojects:
Copy code
js(IR) {
    useCommonJs()

    browser {
        testTask {
           enabled = false
        }
    }

    binaries.executable()
}
But when I try to call methods on the build of SubProjectC, it says it cannot find the nested dependencies (i.e. SubProjectA/SubProjectB). Anyone know of any sample projects out there with this sort of layout?
t
Do you use
api
or
implementation
dependency configuration for
A
and
B
?
j
This is what it looks like in `C`'s `build.gradle.kts`:
Copy code
sourceSets {
        all {
            languageSettings.apply {
                useExperimentalAnnotation("kotlin.RequiresOptIn")
                useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
                useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi")
            }
        }

        named("commonMain") {
            dependencies {
                implementation(kotlin("stdlib-jdk8"))
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version")
                api(project(":SubProjectB"))
            }
        }

        named("commonTest") {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation(kotlin("reflect"))
                implementation(project(":SubProjectA"))
            }
        }
 
        named("jsMain") {
            dependencies {
                implementation(kotlin("stdlib-js"))
                api(project(":SubProjectB"))
            }
        }

        named("jsTest") {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
    }
And in `B`'s `build.gradle.kts`:
Copy code
sourceSets {
        all {
            languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
            languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
            languageSettings.useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi")
        }

        named("commonMain") {
            dependencies {
                implementation(kotlin("stdlib"))
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version")
            }
        }

        named("commonTest") {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation(kotlin("reflect"))
                implementation(project(":SubProjectA"))
            }

            kotlin.setSrcDirs(kotlin.srcDirs + "build/codegen")
        }
        
        named("jsMain") {
            dependencies {
                implementation(kotlin("stdlib-js"))
            }
        }

        named("jsTest") {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
    }
t
If you use
A
api in
C
then you need add this
Copy code
implementation(project(":SubProjectA"))
in
C
project too