3

This is currently my build.gradle file (I removed unnecessary task references, which are not only working perfectly fine, but are irrelevant to the current question):

buildscript {
    repositories {
        jcenter()
        maven {
            name = 'forge'
            url = 'https://files.minecraftforge.net/maven'
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
    }
}

apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'java'

dependencies {
    compile('some.library:here:1.2.3') // no extra modules
    compile('other.library:here:4.5.6') // multiple modules
}

jar {
    from project.configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}

Currently I have a system which will automatically pack all the dependencies into my jar file. The main issue I have is that if another mod or file loads the same library before my mod, I will end up with a class loading problem, because I'll be loading the same class twice (one from another jar, and one from my own).

With that being said, is it possible to avoid such an issue? How would I realistically account for such a thing? Does forge perhaps have a method to control class loading to the extent that duplicate libraries will not be loaded, hence there will be no class conflicts?

1 Answer 1

3

Minecraft Forge supports a feature called shading to deal with this problem. When you shade a jar, it's integrated into your jar, but the package is renamed to something unique (along with all references to it from your code).

Source: https://github.com/MinecraftForge/ForgeGradle/blob/FG_1.2/docs/user-guide/shading.md

4
  • Is there a new link for this guide? that one seems to 404
    – Jaak Kütt
    Commented Nov 1, 2020 at 22:24
  • 1
    @JaakKütt Try it now. Commented Nov 1, 2020 at 23:49
  • The linked guide has a last commit 2015 and does not seem to work anymore, in particular the srgExtra bit. Is there an updated version?
    – Tim Morris
    Commented Jan 11, 2021 at 18:39
  • @Tim Morris change minecraft { srgExtra } to reobf { jar { extraLine { } } } forums.minecraftforge.net/topic/…
    – m-doescode
    Commented Feb 14, 2022 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.