Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError when running binaries generated by Compose Multiplatform Gradle plugin #217

Closed
jedlimlx opened this issue Aug 26, 2024 · 1 comment · Fixed by #220
Closed

Comments

@jedlimlx
Copy link

I get the error below

Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory
        at com.github.ajalt.mordant.internal.MppInternal_jvmKt.runningInIdeaJavaAgent(MppInternal.jvm.kt:57)
        at com.github.ajalt.mordant.terminal.TerminalDetection.isIntellijRunActionConsole(TerminalDetection.kt:199)
        at com.github.ajalt.mordant.terminal.TerminalDetection.detectTerminal(TerminalDetection.kt:19)
        at com.github.ajalt.mordant.terminal.StdoutTerminalInterface.<init>(StdoutTerminalInterface.kt:17)
        at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:52)
        at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:41)
        at org.example.MainKt.main(Main.kt:7)
Caused by: java.lang.ClassNotFoundException: java.lang.management.ManagementFactory
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 7 more

when using the following Main function

import com.github.ajalt.mordant.terminal.Terminal

fun main() = Terminal().println("test")

and the following build.gradle.kts file

import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    kotlin("jvm") version "2.0.0"
    id("org.jetbrains.compose") version "1.6.11"
    id("org.jetbrains.kotlin.plugin.compose") version "2.0.20"
}

group = "org.example"
version = "1.0.0"

repositories {
    mavenCentral()
    google()
}

dependencies {
    implementation("com.github.ajalt.mordant:mordant:2.7.2")
    testImplementation(kotlin("test"))
    implementation("androidx.compose.runtime:runtime:1.6.8")
}

tasks.test {
    useJUnitPlatform()
}

kotlin {
    jvmToolchain(17)
    sourceSets {
        val main by getting
        val test by getting
    }
}

compose.desktop {
    application {
        mainClass = "org.example.MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Pkg, TargetFormat.Exe, TargetFormat.Deb)
        }
    }
}

The full project is attached. I have tested this on both my Windows 11 computer and a WSL instance running Ubuntu 22.04.1 LTS.
mordant_bug.zip

@ajalt
Copy link
Owner

ajalt commented Sep 1, 2024

Thanks for the report. I thought I was already catching that error, but it turns out NoClassDefFoundError is a Throwable, not an Exception.

@ajalt ajalt closed this as completed in #220 Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@ajalt @jedlimlx and others