thedarkcolour / KotlinForForge

Makes Kotlin forge-friendly.
GNU Lesser General Public License v2.1
194 stars 26 forks source link

Modules thedarkcolour.kotlinforforge and kotlin.stdlib export package kotlin to module fml_language_lowcode #93

Closed forpleuvoir closed 6 months ago

forpleuvoir commented 10 months ago

My English is not good, so I use AI for translation. I am developing Forge and Fabric mods using Architectury Loom. I have dependent my own utility library, but when debugging on the Forge side, I cannot start the game normally within IntelliJ IDEA. However, when I package the mod as a JAR and place it in the actual game, it works fine.

Exception in thread "main" java.lang.module.ResolutionException: Modules thedarkcolour.kotlinforforge and kotlin.stdlib export package kotlin to module fml_language_lowcode
    at java.base/java.lang.module.Resolver.resolveFail(Resolver.java:901)
    at java.base/java.lang.module.Resolver.failTwoSuppliers(Resolver.java:815)
    at java.base/java.lang.module.Resolver.checkExportSuppliers(Resolver.java:736)
    at java.base/java.lang.module.Resolver.finish(Resolver.java:380)
    at java.base/java.lang.module.Configuration.<init>(Configuration.java:140)
    at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:494)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.10/cpw.mods.modlauncher.ModuleLayerHandler.buildLayer(ModuleLayerHandler.java:75)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.10/cpw.mods.modlauncher.ModuleLayerHandler.buildLayer(ModuleLayerHandler.java:87)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.10/cpw.mods.modlauncher.Launcher.run(Launcher.java:94)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.10/cpw.mods.modlauncher.Launcher.main(Launcher.java:78)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.10/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)
    at MC-BOOTSTRAP/cpw.mods.modlauncher@10.0.10/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)
    at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141)
    at net.fabricmc.devlaunchinjector.Main.main(Main.java:86)
    at dev.architectury.transformer.TransformerRuntime.main(TransformerRuntime.java:219)

This is the source code of the problematic MOD. This is the source code of the Kotlin library being referenced.

KP2048 commented 9 months ago

@thedarkcolour bump please I am also having this issue. It seems to work fine with the neoforge version on Architectury, but regular Minecraft forge causes this error.

KP2048 commented 9 months ago

The specific module and package seem to change too, (race condition on which one gets displayed in the error message maybe?) For example I just got this one: Modules thedarkcolour.kotlinforforge and kotlin.stdlib export package kotlin.text to module net.minecraftforge.javafmlmod

thedarkcolour commented 9 months ago

A while ago I tried to investigate this issue and found that something weird was going on with classloading. The main classloader is set up correctly, but when a method from a library was called, it would use a different classloader all of a sudden and try to load Kotlin libs in that classloader which was not set up correctly. I'll look into it again later this week.

KP2048 commented 9 months ago

I found a workaround until you get it fixed. If I add this to the top of the forge dependencies block, it seems to work

    compileOnly(kotlin("stdlib"))
KP2048 commented 9 months ago

A while ago I tried to investigate this issue and found that something weird was going on with classloading. The main classloader is set up correctly, but when a method from a library was called, it would use a different classloader all of a sudden and try to load Kotlin libs in that classloader which was not set up correctly. I'll look into it again later this week.

If I forcibly make the stdlib compileOnly, it seems to fix it so that it uses the correct classloader

thedarkcolour commented 9 months ago

How can you do this in a Groovy buildscript?

KP2048 commented 9 months ago

compileOnly(kotlin("stdlib")) translates to compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:<kotlin version>'

KP2048 commented 9 months ago

You may need to add a version, unsure about that

Edit: the kotlin DSL kotlin() function defaults to whatever your kotlin Gradle plugin version is, in my case 1.9.20

KP2048 commented 9 months ago

I just added that dependency to my dependencies block in the forge subproject and it more or less fixed it. I did run into a strange issue where forge sometimes can't find my mod object, it might be a race condition because sometimes it works sometimes it doesn't. It probably only happens in a dev environment though

forpleuvoir commented 9 months ago

I just added that dependency to my dependencies block in the forge subproject and it more or less fixed it. I did run into a strange issue where forge sometimes can't find my mod object, it might be a race condition because sometimes it works sometimes it doesn't. It probably only happens in a dev environment though

I have tried this before, but it didn't work

KP2048 commented 9 months ago

I do get this sometimes on the forge project:

The following classes are missing, but are reported in the mods.toml: [...]

It doesn't happen on fabric or NeoForge, it's definitely set up correctly and I hope it doesn't happen in production

thedarkcolour commented 6 months ago

Same root cause as #86 so I'm marking as duplicate