Kotlin Compose Desktop. "Failed to launch JVM" with executable file

223 Views Asked by At

I am creating a simple pet project using a technology that is new to me - Kotlin Compose Desktop. The project is primitive, something like CRUD with h2 (in file) database. So, now I have a problem with the gradle task packageMsi. When the msi file is ready and I install my program on Windows system, there is an error "Failed to launch JVM" when I run an exe file.

There is my gradle script:

import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import kotlin.script.experimental.jvm.util.classpathFromClass

plugins {
    kotlin("jvm") version "1.9.21"
    id("org.jetbrains.compose") version "1.5.11"
}

group = "org.makariyp"
version = "1.0"

repositories {
    google()
    mavenCentral()
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

dependencies {
    testImplementation("org.jetbrains.kotlin:kotlin-test:1.8.10")
    implementation(compose.desktop.currentOs)
    implementation("com.h2database:h2:2.2.224")
}

tasks.test {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile>() {
    kotlinOptions.jvmTarget = "17"
    kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}

compose.desktop {
    application {
        mainClass = "org.makariyp.MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "RepeaterNow"
            packageVersion = "1.0.0"
            modules("java.sql")
            macOS {
                iconFile.set(project.file("src\\main\\resources\\icon.icns"))
            }
            windows {
                iconFile.set(project.file("src\\main\\resources\\icon.ico"))
            }
            linux {
                iconFile.set(project.file("src\\main\\resources\\icon.png"))
            }
            buildTypes.release.proguard {
                isEnabled.set(false)
            }
        }
    }
}

First I had the same problem with the runDistributable task, but I solved it by adding modules("java.sql") in the gradle build file, now gradle does this task and the app runs successfully. But I still have problems with the packageMsi. How can I solve this?

In my suggestion, the problem is related to dependencies that don't exist in the wix installer and finally in the exe file. But on the 3rd day I can't find a solution. I have also tried different versions of kotlin, gradle and h2.

0

There are 0 best solutions below