Arjan van Wieringen
04/09/2022, 3:35 PMArjan van Wieringen
04/09/2022, 3:36 PM// 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)
}
}
}
Arjan van Wieringen
04/09/2022, 3:36 PM// 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"))
}
}
}
}
Arjan van Wieringen
04/09/2022, 3:37 PMrootProject.name = "kotlin"
include("dom")
include("mvu") // when adding this one, everything breaks and dom module get's unloaded...
Arjan van Wieringen
04/09/2022, 3:40 PMArjan van Wieringen
04/09/2022, 3:43 PMAnton Lakotka [JB]
04/09/2022, 9:49 PMdom/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:
// settings.gradle.kts
pluginManagement {
plugins {
kotlin("multiplatform") version "1.6.20"
}
}
rootProject.name = "hmpp-lib"
include("dom")
include("mvu")
// ./build.gradle.kts
plugins {
kotlin("multiplatform") apply false
}
allprojects {
repositories {
mavenCentral()
}
}
// 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)
}
}
}
// 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!Arjan van Wieringen
04/10/2022, 5:41 AMArjan van Wieringen
04/10/2022, 8:32 AM