By default, Minecraft Forge does not load dependencies from the classpath unless they are explicitly declared as mods. These steps outline how to remedy this. This guide assumes that:
- You are on ForgeGradle 5 or higher.
- You are on Forge 1.17.1 (37.0.13) or higher.
To configure your Java libraries to be loaded by Forge, you should use the minecraftLibrary
configuration provided by ForgeGradle.
You now must make sure to declare your dependencies using minecraftLibrary
configuration.
For example, you may have a line in dependencies {}
that looks something like this:
minecraftLibrary 'com.example:examplething:1.0.0'
When using regular Java libraries not provided by Minecraft Forge, it is important to keep in mind that these libraries will disappear when you build your mod jar by default. This means the libraries will no longer exist when we try to use them from a normal Minecraft Forge installation. To fix this, you must set up either shading or Jar-in-Jar.
This can be done by configuring the gradle shadow plugin. See this guide which is specific to Minecraft Forge.
See this article on the Forge Community Wiki and consult the Forge discord for help.
Hey @SizableShrimp, thanks your Gists have helped a lot!
Unfortunately, with Forge 1.18.2 I'm still having troubles. Your snippet changed the classpath correctly* but at runtime I stell get ClassNotFoundException for my dependencies.
Edit: I'm using the Gradle
runServer
task*) I checked the java start params with ProcessExplorer and the needed jar was there and I checked it contains the right classes