ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
982 stars 34 forks source link

Fix native image support #201

Closed hubvd closed 2 months ago

hubvd commented 2 months ago

This should solve GraalVM native image issues. See commits for details.

I tried the select sample and a personal project locally on linux X64 using

With Java 8, it fails

Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Class.getModule()Ljava/lang/Module;
    at com.github.ajalt.mordant.terminal.terminalinterface.ffm.TerminalInterfaceProviderFfm.load(TerminalInterfaceProvider.ffm.kt:10)
    at com.github.ajalt.mordant.internal.MppInternal_jvmKt.getStandardTerminalInterface(MppInternal.jvm.kt:139)
    at com.github.ajalt.mordant.internal.MppInternalKt.<clinit>(MppInternal.kt:60)
    at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:49)
    at com.github.ajalt.mordant.samples.MainKt.main(main.kt:9)
    at com.github.ajalt.mordant.samples.MainKt.main(main.kt)

And with java 11 and 17

Exception in thread "main" java.lang.NoSuchMethodError: 'boolean java.lang.Module.isNativeAccessEnabled()'
    at com.github.ajalt.mordant.terminal.terminalinterface.ffm.TerminalInterfaceProviderFfm.load(TerminalInterfaceProvider.ffm.kt:10)
    at com.github.ajalt.mordant.internal.MppInternal_jvmKt.getStandardTerminalInterface(MppInternal.jvm.kt:139)
    at com.github.ajalt.mordant.internal.MppInternalKt.<clinit>(MppInternal.kt:60)
    at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:49)
    at com.github.ajalt.mordant.samples.MainKt.main(main.kt:9)
    at com.github.ajalt.mordant.samples.MainKt.main(main.kt)

I'm assuming this can be solved using a multi release jar (or a try catch :thinking:).

A few more things I noticed,

ajalt commented 2 months ago

Thank you!! This looks excellent! I'll fix the windows builds.

The binary incompatibility was deliberate; it's why I've waited to long to make a clikt release. I'm going to release this as mordant 3.0, then include it in clikt 5.0.