I am trying to make a KMP template project that uses platform specific languages/UI (Android with xml views, ios with swift and view controllers, desktop with Javafx UI).
I started from the KMP Wizard that does not share UI as a baseline and the first thing I wanted to do was add the desktop module to it.
In the root of the project I added a desktop
directory and then in my settings.gradle.kt
I added in
include(":desktop")
so the module is recognized. I then created a new Javafx project in Intellij and copied the build.gradle.kt file from it along with the source and copied that into the desktop folder of the KMP project so it looks like this
-desktop
-src
-main
-java
-kotlin
-resources
-build.gradle.kt
desktop build.gradle
plugins {
java
alias(libs.plugins.kotlinMultiplatform)
application
alias(libs.plugins.javaModularity)
alias(libs.plugins.javafxPlugin)
alias(libs.plugins.jlinkPlugin)
}
group = "com.example.desktop"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
val junitVersion = "5.10.0"
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
application {
mainModule = "com.example.desktop.demo2"
mainClass.set("com.example.desktop.demo2.HelloApplication")
}
kotlin {
jvm("desktop") {
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
sourceSets {
val desktopMain by getting
val commonMain by getting {
dependencies {
// Reference to the shared module
implementation(projects.shared)
}
}
desktopMain.dependencies{
}
}
}
javafx {
version = "20.0.1"
modules = listOf("javafx.controls", "javafx.fxml")
}
dependencies {
implementation(projects.shared)
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
}
tasks.test {
useJUnitPlatform()
}
jlink {
imageZip.set(project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip"))
options = listOf("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
launcher {
name = "app"
}
}
tasks.register("jlinkZip2") {
group = "distribution"
}
but the desktop module is not even recognized as something that can be run. I linked the whole repo above, I thought at one point this was something that was possible how can I get a desktop module in a KMP project that uses javafx UI and not compose?