About Contact

The tutorial text is available under the CC BY-SA 4.0 License. Any code in the tutorial is Public Domain, feel free to use it in your own projects.

Adding Dependencies to Your Minecraft Mod

Sometimes you'll want gradle to load other libraries or mods so you can access their code. Most of the work will be done in your build.gradle file.

Dependencies Block

dependencies {
    <function> <descriptor>

The function tells gradle when it should load the dependency.

The descriptor tells it what dependency to load. But you must define urls to repositories where it can download the files for the dependencies you declare.

Wrapping the descriptor string in the fg.deobf function will tell forge to deobfuscate that jar which lets you use compiled mods in your development environment.

Repository Sources

Project Repo

Many mods specifically intended to be libraries used by other developers will provide their own public maven repository for you to use. Make sure to read the specific project's documentation (curseforge description, github readme, wiki, etc) and see how they recommend depending on them. For example, Geckolib has an installation wiki page that shows how to reference their cloudsmith maven repository. If the project you want to depend on doesn't provide something just use one of the options below that will work regardless.


If you want to get a mod directly from curseforge you can use cursemaven.com.

repositories {
    maven {
        url &quot;https://cursemaven.com&quot;

dependencies {
    implementation fg.deobf('curse.maven:Descriptor-ProjectID>:FileID')

Here's an example that adds Repurposed Structures: https://github.com/LukeGrahamLandry/mercenaries-mod/blob/main/build.gradle#L150-L152


If you want to get a mod from directly from github you can use jitpack.io. It will be a bit slow the first time because they have to checkout and build the project before they can serve it to you. You can go to their website and trigger a build of the correct version of your repository ahead of time so its ready when you need it. Note that the main artifact built will be the normal mod jar so you must tell ForgeGradle to deobfuscate it for use in your development environment.

repositories {
    maven { url 'https://jitpack.io' }

dependencies {
    implementation fg.deobf('com.github.UserName:RepoName:Version')

The version should be the tag name of a github release. If the repository doesn't have any releases published, you can use the short commit hash (which you can find on the commits page) instead of the version. You can also use branchname-SNAPSHOT to get the latest version.

Your Computer

If you want to temporarily depend on a jar file without dealing with finding a maven repo to host it, you can load it directly from your computer's file system. This has a big disadvantage in that anyone who wants to work with your mod's code has to go find the right jar files and put them in the right places. If you want to help others contribute to your project, go with one of the other maven repository sources above.

repositories {
    flatDir {
        dirs '/path/to/libs/folder'

dependencies {
    implementation fg.deobf('tld.packagedomain.mod:Name:Version')

The descriptor above will first search for /path/to/libs/folder/Name-Version.jar and then if that isn't found /path/to/libs/folder/Name.jar .

If you use Name-Version instead of Name:Version , it will still find the same jar file but the fg.deobf function will crash because it tries to name the remapped artifact based on the version which it only gets by splitting the artifact descriptor on :


You should add an entry to the bottom of your mods.toml file. This will give users a more meaningful crash message when they try to start the game without the required mod. Base it off the format of the minecraft and forge dependencies in the default mods.toml from the mdk.


Shading a dependency allows you to bundle it into your mod's built jar file so players don't need to install it separately.

On fabric you could just use the include function but old versions of forge make it way more work. Forge 1.19 and later alleges to natively support the JarJar library for including other mod jars within yours so you can take a look at the Jar-In-Jar forge community wiki page instead (ONLY FOR 1.19+). This should even work for jars that forge needs to load as mods. For older versions, read on!

Shading has a few disadvantages:

How To:


Mixin is a powerful framework that allows you to directly modify Minecraft's byte code at runtime. You can use mixins to modify the byte code of other mods, just like you would vanilla Minecraft. It's not very safe to do this however since mods are likely to change drastically between versions with no warning. This means that although your mixin works fine for the version of your dependency you test with, if the mods updates to add a new feature, the method you target may disappear or the code within may change enough that whatever you're doing no longer works properly. It will probably be lots of effort to keep your mixins functional over an extended period of time. A more future proof option may be to find your dependency on github and make a pull request that adds an API that makes whatever you're doing easy.

My mixins tutorial is incomplete. See other resources:

Remember that your inject annotation must have remap=false when targeting methods added by other mods (or forge itself). This is because mixin automatically tries to remap everything according to your project's mappings settings but will get confused because the other mod won't have a remapped name since it was never obfuscated.

Mixin Plugins

Fixing Error With Other Mod's Mixins

Mixin can get a bit confused when you depend on a mod that needs to add its own mixins but uses different mappings than you do. To fix this, in your build.gradle, add the following to your client and server definitions within the run block.

property 'mixin.env.remapRefMap', 'true'
property 'mixin.env.refMapRemappingFile', &quot;${projectDir}/build/createSrgToMcp/output.srg&quot;

Class Loading

For soft dependencies you should check that the mod is loaded before trying to reference any of its code so it doesn't crash when the dependency isn't available.

TODO: example

Final Thoughts

Please don't be one of those people that makes a bullshit library mod just to farm ad income on curse forge. It's so fucking annoying. It makes it that much more of a pain in the ass for other people to work with your mod's code (they have to setup two projects to actually be able to change anything). It's also a waste of time for players that don't use the curse forge launcher since they have to go install the library as well. This extra time adds up if every mod author makes the genius discovery that you earn a couple extra cents if you split up all your mods into several. Take a look at serilum's mods, I'll give you a hint, despite having almost a hundred projects, they only have one mod there. The majority of the functionality is in the library and they use many tiny mods to enable features instead of just having a fucking config like a sane person. Or for a more direct example, extreme reactors depends on zero core, a library that you can tell is really useful because... nothing else depends on it. Let's take a wild guess at why the author choose to do that.

That's not to say there are no good library mods. Geckolib, Patchouli, Curios, and Architectury, to name a few, single handedly save developers hundreds of hours. Just try to be one of the useful ones.

Got Questions? Join the Discord!

View Full Tutorial Code on Github!

Donate to Support Tutorial Creation!

See Page Edit History