Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Koltin Multiplatform Multi Module JVM/JS Project Setup

I need to convert existing multi-module jvm project into a multiplatform project.

//Exisiting Modules: (JVM Project)
core
data
app
app_server
utils
db
//Need to add:
app_frontend (Kotlin/JS)

Need to share data module between JVM and JS Thanks in advance.

like image 524
wishnuprathikantam Avatar asked Mar 04 '26 16:03

wishnuprathikantam


1 Answers

I'm assuming you want to share your data module between JVM and JS. For this, your data module has to be a multiplatform project targeting JVM and JS. The most basic setup would be:

// build.gradle.kts

plugins {
    kotlin("multiplatform")
}

group = "data"

kotlin {
    jvm()
    js { browser { binaries.executable() } }

    sourceSets["commonMain"].dependencies {
        // Your dependencies...
    }
}

Other modules can be built with "regular" plugins targeting a specific platform, so your JVM modules won't need any adjustments. The basic setup for JS would be:

plugins {
    id("org.jetbrains.kotlin.js")
}

group = "app_frontend"

dependencies {
    implementation(project(":data"))
    implementation(kotlin("stdlib-js"))
}
kotlin {
    js {
        browser { binaries.executable() }
    }
}

Also checkout the official documentation about multiplatform programming:

  • https://kotlinlang.org/docs/mpp-intro.html
  • https://kotlinlang.org/docs/multiplatform-library.html#creating-a-project
like image 156
pnzr Avatar answered Mar 06 '26 05:03

pnzr