utopia-rise / godot-kotlin-jvm

Godot Kotlin JVM Module
MIT License
585 stars 38 forks source link

java 11 module support #235

Open Frontrider opened 3 years ago

Frontrider commented 3 years ago

Some java 11 modules do not make it to the classpath of the application. This can be a feature as we strip the things we don't need.

Java modules should be taken a look at somewhere down the line.

Godot-JVM: Starting GC thread
WARNING: JNI local refs: 66, exceeds capacity: 65
Godot-JVM: Loading classes ...
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Time
        at com.google.gson.Gson.<init>(Gson.java:265)
        at com.google.gson.Gson.<init>(Gson.java:186)
        at hu.frontrider.skyforge.model.DataLoader.loadData(DataLoader.kt:53)
        at hu.frontrider.skyforge.model.DataLoader.loadModel(DataLoader.kt:17)
        at hu.frontrider.skyforge.Simple._ready(Simple.kt:26)
        at godot.hu.frontrider.skyforge.SimpleRegistrar$register$1$1$2.invoke(SimpleEntry.kt:18)
        at godot.hu.frontrider.skyforge.SimpleRegistrar$register$1$1$2.invoke(SimpleEntry.kt:13)
        at godot.core.KtFunction0.invokeKt$godot_runtime(Functions.kt:103)
        at godot.core.KtFunction.invoke(Functions.kt:74)
Caused by: java.lang.ClassNotFoundException: java.sql.Time
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 9 more
ERROR: check_exceptions: Godot-JVM: An exception has occurred!
   At: modules/kotlin_jvm/src/jni/env.cpp:61.
Godot-JVM: Unloading classes ...
Godot-JVM: Closing GC thread

May not be because of modules, but that is my guess.

piiertho commented 3 years ago

Hello ! Can you try to add sql module to the jre in your project using jlink --add-modules java.base,java.logging,java.sql --output jre ?

Frontrider commented 3 years ago

That command made a new jre folder inside the project's folder.

After further fiddling, this is the point when intellij stopped complaining about missing classes again, compilation fails. https://gist.github.com/Frontrider/840406ffa79fbe402f8f0cfc943d189b

With this setup, it finds the modules that we need, and I'm finally getting errors that I may not be able to resolve from my script. I think I need to exclude godot.runtime from the build. https://gist.github.com/Frontrider/60f830de511cd087defe16f8c42d03a8

The module info was a requirement, and for gamedev I'd say it's an absolute must to trim out the fat from our result.

It also looks like that Kotlin may or may not play well with modules yet, if you only have kotlin code and that requires some hacking like setting the kotlin output directory to the same folder as java.

chippmann commented 3 years ago

@Frontrider Could you comment these two lines: https://github.com/utopia-rise/godot-kotlin-jvm/blob/39828684e65b7d5c717a716c3d02911f74d4d4ad/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/setupConfigurationsAndCompilations.kt#L57 and https://github.com/utopia-rise/godot-kotlin-jvm/blob/39828684e65b7d5c717a716c3d02911f74d4d4ad/kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/setupConfigurationsAndCompilations.kt#L68 build the engine and try again? My guess is that this excludes your module information from the resulting jar. But that's just a guess. Or provide a minimal reproduction sample so i can test that myself?

nicola-sorace commented 1 year ago

I think I might be having a similar issue getting the Exposed library to work:

Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Driver
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:383)
    at java.base/java.lang.Class.forName(Class.java:376)
    at org.jetbrains.exposed.sql.Database$Companion.connect(Database.kt:204)
    at org.jetbrains.exposed.sql.Database$Companion.connect$default(Database.kt:195)
    at com.example.galaxyStream.universe.SubstanceKt.connectDatabase(Substance.kt:162)
    at com.example.galaxyStream.universe.Galaxy._ready(Galaxy.kt:59)
    at godot.com.example.galaxyStream.universe.GalaxyRegistrar$register$1$1$2.invoke(GalaxyRegistrar.kt:19)
    at godot.com.example.galaxyStream.universe.GalaxyRegistrar$register$1$1$2.invoke(GalaxyRegistrar.kt:19)
    at godot.core.KtFunction0.invokeKt$godot_library(Functions.kt:103)
    at godot.core.KtFunction.invoke(Functions.kt:74)
    at godot.core.TransferContext.icall(Native Method)
    at godot.core.TransferContext.callMethod(TransferContext.kt:52)
    at godot.Node.addChild(Node.kt:806)
    at godot.Node.addChild$default(Node.kt:804)
    at com.example.galaxyStream.network.JoinServer._process(JoinServer.kt:266)
    at godot.com.example.galaxyStream.network.JoinServerRegistrar$register$1$1$11.invoke(JoinServerRegistrar.kt:28)
    at godot.com.example.galaxyStream.network.JoinServerRegistrar$register$1$1$11.invoke(JoinServerRegistrar.kt:28)
    at godot.core.KtFunction1.invokeKt$godot_library(Functions.kt:113)
    at godot.core.KtFunction.invoke(Functions.kt:74)
Caused by: java.lang.ClassNotFoundException: java.sql.Driver
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 30 more

This is pretty much just their getting started guide so that might be a minimal reproduction example. Will try commenting out the lines you mentioned but I haven't tried compiling the engine before.

nicola-sorace commented 1 year ago

@chippmann That file seems to have disappeared. Found it here instead, is this the line to comment out now?

https://github.com/utopia-rise/godot-kotlin-jvm/blob/d0b594db3a2a06e1f52879c65e5ad6b1555498c7/kt/godot-library/build.gradle.kts#L44

chippmann commented 1 year ago

@nicola-sorace Did you try to add the sql modules first? Probably this will be enough: jlink --add-modules java.base,java.logging,java.sql --output jre-amd64 but maybe you need additional modules