Skip to content

Instantly share code, notes, and snippets.

@SizableShrimp
Last active March 24, 2024 14:39
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SizableShrimp/66b22f1b24c255e1491c8d98d3f11f83 to your computer and use it in GitHub Desktop.
Save SizableShrimp/66b22f1b24c255e1491c8d98d3f11f83 to your computer and use it in GitHub Desktop.
How to fix Java libraries not loading in Minecraft Forge 1.17+

How to fix Java libraries not loading in Minecraft Forge 1.17+

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:

  1. You are on ForgeGradle 5 or higher.
  2. You are on Forge 1.17.1 (37.0.13) or higher.

Using Java libraries

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'

A note on production differences

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.

Shading

This can be done by configuring the gradle shadow plugin. See this guide which is specific to Minecraft Forge.

Jar-in-Jar

See this article on the Forge Community Wiki and consult the Forge discord for help.

@Hades32
Copy link

Hades32 commented Jul 21, 2022

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

@SizableShrimp
Copy link
Author

@Hades32 Please use the forge discord at https://discord.gg/forge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment