For the life of me I can't get 2 separate MPP modu...
# multiplatform
a
For the life of me I can't get 2 separate MPP modules working inside one project. I have 2 projects: • dom • mvu (which should refer to dom) I get errors ranging from "Projects must be configuring" to modules not loading tat all. Besides that, Gradle is complaining that I don't have configured any JS module, which I have.
Copy code
// dom/build.gradle.kts

plugins {
    kotlin("multiplatform") version "1.6.20"
}

rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
}

group = "nl.avwie"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {
    jvm()
    js("jsCore", IR)

    js("demo", IR) {
        browser()
        binaries.executable()
    }

    js("stress", IR) {
        browser()
        binaries.executable()
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }

        val jsCoreMain by getting {
            dependencies {
                implementation(npm("virtual-dom", "2.1.1"))
            }
        }

        val demoMain by getting {
            dependsOn(jsCoreMain)
        }

        val stressMain by getting {
            dependsOn(jsCoreMain)
        }
    }
}
Copy code
// mvu/build.gradle.kts
plugins {
    kotlin("multiplatform") version "1.6.20"
}

rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
}

group = "nl.avwie"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {

    js {
        browser()
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(project(":dom"))
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
    }
}
And my settings file:
Copy code
rootProject.name = "kotlin"
include("dom")
include("mvu") // when adding this one, everything breaks and dom module get's unloaded...
I am running the latest IntelliJ and Kotlin Plugin
a
Hey Arjan! This seemed like a bug to me. Could you please report an issue in YT? (we'll try our best to fix it). The issue seems related to the fact that you have some JS target without browser or nodejs specification. So please report it 🙏 Nevertheless, I think you are misconfiguring your Project setup. Looking at your
dom/build.gradle.kts
So the first question is what exact artifacts you are expecting to be built? My assumption is that you don't want
jsCommon
to be actually published as a separate artifact. Instead, you want to lift some common code for both
stress
and
demo
which are the exact artifacts you want to produce. Is that correct? If so, then you don't need to declare a separate "JS target with name jsCommon, instead, you should benefit from HMPP functionality and create an intermediate sourceset
jsCommon
. And make
stressMain
and
demoMain
depending on it. If my assumption is wrong, and you need
jsCommon
to be created (and published?) as a separate artifact in that case you should lift it to another project. Another aspect is mostly a recommendation but still good to remember. Kotlin Gradle Multiplatform (KGP) plugin is a complex tool that is designed to work with multiple gradle projects (it is needed for example for fine-tune dependency resolution between sourcesets of different projects). And therefore it is recommended to synchronize KGP versions among all projects. In your example, you have applied
kotlin(multiplatform)
plugin for both projects with specified version. It might cause some troubles when versions go out of sync. Instead, the recommended way is to declare plugin through Gradle's
pluginManagement
in
settings.gradle.kts
. And then you can apply plugins in all projects without specifying a version. And finally, it is recommended to declare
kotlin(multiplatform)
plugin in the Gradle Root project. In case Kotlin isn't meant to be used in the root project, then you just don't apply it:
plugins { kotlin("multiplatform") apply false }
So these are updated scripts that make your project work:
Copy code
// settings.gradle.kts
 pluginManagement {
    plugins {
        kotlin("multiplatform") version "1.6.20"
    }
}

rootProject.name = "hmpp-lib"

include("dom")
include("mvu")
Copy code
// ./build.gradle.kts
plugins {
    kotlin("multiplatform") apply false
}

allprojects {
    repositories {
        mavenCentral()
    }
}
Copy code
// dom/build.gradle.kts
plugins {
    kotlin("multiplatform")
}

rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
}

group = "nl.avwie"
version = "1.0-SNAPSHOT"

kotlin {
    jvm()

    js("demo", IR) {
        browser()
        binaries.executable()
    }

    js("stress", IR) {
        browser()
        binaries.executable()
    }

    sourceSets {
        val commonMain by getting

        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }

        val jsCoreMain by creating {
            dependencies {
                implementation(npm("virtual-dom", "2.1.1"))
            }
            dependsOn(commonMain)
        }

        val demoMain by getting {
            dependsOn(jsCoreMain)
        }

        val stressMain by getting {
            dependsOn(jsCoreMain)
        }
    }
}
Copy code
// mvu/build.gradle.kts
plugins {
    kotlin("multiplatform")
}

rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
}

group = "nl.avwie"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {

    js {
        browser()
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(project(":dom"))
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
    }
}
Please let me know if still have questions!
a
Wow! Thanks for the detailed answer. It may be absolutely true that I misconfigured something, so Ill look into that now. Will come back to you
@Anton Lakotka [JB] It was indeed an error on my part. After your suggestions I split the modules in a different way and everything works as expected!
👍 1