-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Unable to use other Kotlin libraries with KFF on Forge/NeoForge #86
Comments
Here are the dependencies for forge using Architectury's |
Possibly related: |
To use Kotlin For Forge in Architectury you must use "implementation" instead of "forgeImplementation" |
I am using implementation: https://github.com/Erdragh/AstralBot/blob/main/forge/build.gradle.kts |
According to the Architectury Discord this may be caused by okhttp3 not having access to kotlin because it's in the bootstrap class loader, while KFF's kotlin stdlib is in the mod class loader. I don't know enough about forge and especially forge's class loading to give any specifics tho. |
If you compile your mod and run it in a Forge instance outside of IntelliJ, does it still crash? |
It does crash but because of a different thing, it can't load the Apache collections things, but that's because from what I can tell they're just not there and I need to Edit: said crash also happens when running the built fabric jar on a fabric server, so it's not a forge issue. |
You may need to add the Kotlin dependencies to Gradle yourself. If that doesn't work, I know on ForgeGradle there is a snippet that gets shared around on the server with the command |
Could you elaborate on that first part a bit? I'm kind of new to gradle and have been reading a lot of documentation, but haven't wrapped my head around everything just yet |
Is your buildscript a build.gradle or a build.gradle.kts? |
I've linked the repo, it's all completely .kts |
Add this to your dependencies block: // Default classpath
api(kotlin("stdlib"))
api(kotlin("stdlib-common"))
api(kotlin("stdlib-jdk8"))
api(kotlin("stdlib-jdk7"))
api(kotlin("reflect")) |
Didn't fix it. The equivalent of
and more for each specified dependency |
You might need to try something else besides what I gave you, since gradle cannot find kotlin for some reason |
I've tested with a debugger and it looks like okhttp3 is being loaded on a different classloader than JDA. When stepping into the setter for Dispatcher.maxRequestsPerHost, you can use the Evaluate Expression tool to see that |
I encountered what I think is the same issue while trying to use Ktor on Forge with Architectury, and I came up with a slightly hacky workaround that seems to work pretty well. As you said, I think the issue is that I'm not sure if there's a better way to fix this in dev, but my workaround was to create a Gradle artifact transform that adds Links:
I think this is also the same issue behind #94. |
This issue happens because Kotlin for Forge shadows the Kotlin standard libraries, when it should be using JarJar to include them. However, due to an issue in Forge/NeoForge this is not possible. Worth mentioning that this issue has been fixed in Kotlin for Forge 5.0.0 on NeoForge 1.20.5. |
Just to confirm, are JarJar libraries loaded onto the Boot or MC-BOOTSTRAP layer? If not, I'd think this would still be an issue in the dev environment, wouldn't it? |
JarJar libraries are loaded onto the GAME layer. |
This should be fixed on Kotlin for Forge 5.x |
Is it possible to backport this to 4.x ? |
It is, but only on very recent versions of Forge. |
Which versions ? Before the bootstrap update ? |
For 1.20.1:
For 1.19.2:
|
I see that your fix was merged in 1.20.4 MinecraftForge/MinecraftForge#10022 but the issue seems to persist even on the latest version in dev environment KFF is implemented with the
|
What do you mean by latest version? I only really wrote documentation for 1.21+ because that's the only relevant versions for which it is fixed (but this should work for 1.20.4 too) |
The issue happens in my dev environment only You said that the issue was fixed in 1.19 to 1.21, right ? |
Yeah Loom tends to break stuff |
I'm gonna wait for a follow-up from the maintainer and get back to you afterward |
This should now work in latest Forge/NeoForge thanks to this PR: MinecraftForge/MinecraftForge#9939 |
I'm going to test this and I'll get back to you to confirm |
I haven't back ported to 4.x since it's in a very recent version of Forge, but I can do that if necessary |
That would be greatly appreciated |
I'm writing a Minecraft mod / Discord bot combo: https://github.com/Erdragh/AstralBot
It uses JDA to communicate with Discord. JDA has a dependency on okhttp3 which over multiple corners has a dependency on the kotlin stdlib. I'm excluding the
org.jetbrains.kotlin
dependency from JDA.I'm using Kotlin for the Mod itself and the build scripts. The Fabric server starts fine, the Forge server doesn't.
To reproduce:
DISCORD_TOKEN
set to any value, just so it's defined.The relevant exception is the following: https://gist.github.com/Erdragh/c84543358f069f43e16e90fb55665324
I'm not sure whether this is an Architectury or a KFF issue, I've already made a support post on the Architectury Discord with no result.
What I find weird is that
kotlin.reflect
is apparently loading fine judging from the stack trace, butkotlin/Unit
just can't be found.The text was updated successfully, but these errors were encountered: