ajalt / clikt

Multiplatform command line interface parsing for Kotlin
https://ajalt.github.io/clikt/
Apache License 2.0
2.53k stars 120 forks source link

Error message "java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory" when running as distributable #522

Closed Claudius42 closed 4 months ago

Claudius42 commented 4 months ago

Hi All,

First of all thanks for the great library! I already use it in my first kotlin multiplatform project and it works great when running within the IDE. However, when I create a distributable I face following error message.

Do you have any idea what mights be the reason for this error message?

Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory at com.github.ajalt.mordant.internal.MppInternal_jvmKt.runningInIdeaJavaAgent(MppInternal.jvm.kt:51) at com.github.ajalt.mordant.terminal.TerminalDetection.isIntellijRunActionConsole(TerminalDetection.kt:196) at com.github.ajalt.mordant.terminal.TerminalDetection.detectTerminal(TerminalDetection.kt:16) at com.github.ajalt.mordant.terminal.StdoutTerminalInterface.(StdoutTerminalInterface.kt:17) at com.github.ajalt.mordant.terminal.Terminal.(Terminal.kt:52) at com.github.ajalt.mordant.terminal.Terminal.(Terminal.kt:41) at com.github.ajalt.clikt.core.Context$Builder.(Context.kt:266) at com.github.ajalt.clikt.core.Context$Companion.build$clikt(Context.kt:351) at com.github.ajalt.clikt.core.CliktCommand.createContext(CliktCommand.kt:140) at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:455) at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:454) at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:474) at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:481) at com.conscience.tool.log_analyser.MainKt.main(main.kt:14) 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) ... 14 more

Many thanks in advance, Claudius

ajalt commented 4 months ago

How are you creating and running the distributable? You said multiplatform, are you seeing this error on JVM? If so, what JDK version are you using?

Claudius42 commented 4 months ago

First of all, thanks for your prompt response!

I do use IntelliJ IDE. The project use Gradle version 8.8, JDK 21. I tested it within the IDE and also on the command line.

ajalt commented 4 months ago

What gradle commands are you using to that trigger this error? I can't reproduce this on my end, are you able to share a small example project that exhibits this error?

Claudius42 commented 4 months ago

I will copy my current project and remove other stuff and then share the project. I will be able to share these things earliest on Monday.

Claudius42 commented 4 months ago

Please find attached a sample project. The task "Tasks / build / run" runs successful. However, the task "Tasks / build / runDistributable" fails within the IDE (I do use IntelliJ), it also fails when running from the command line ('gradle :tool-log-analyser:composeApp:runDistributable build').

sample-clikt.tar.gz

It would be great if you give it try to run it in your environment.

Many thanks in advance!