Jump to content

[CLOSED] [1.18.1] META-INF/libraries not working


Majd123mc

Recommended Posts

Hello,

I am using the Reflections library for my mod. However, when I try to include it using the old ContainedDeps method in 1.18.1, it seems to not work anymore.

Am I doing something wrong, or is this method obsolete now? Should I use shading instead?

pack-libs.gradle

// Create configuration
configurations {
    packLib
    implementation.extendsFrom packLib
}

// afterEvaluate is necessary so that packLib isn't resolved before it is used
afterEvaluate {
    jar {
        // Copy libraries
        from (configurations.packLib) {
            into 'META-INF/libraries'
        }

        // Add libraries into manifest
        //noinspection GroovyAssignabilityCheck
        manifest {
            attributes([
                    "ContainedDeps": configurations.packLib.collect { it.name}.join(' ')
            ])
        }
    }
}

build.gradle

...

// Allows us to pack libraries into jar to be loaded by forge
apply from: 'pack-libs.gradle'

...

dependencies {
    ...
    packLib 'org.reflections:reflections:0.10.2'
}


To clarify, I'm not getting a compilation error, I'm getting a NoClassDefFoundError.
Also, when I build the jar and check inside it, the jars do seem to be there in META-INF/libraries and the ContainedDeps is correct:

ContainedDeps: reflections-0.10.2.jar javassist-3.28.0-GA.jar jsr305-3
 .0.2.jar slf4j-api-1.7.32.jar


 

Edited by Majd123mc
Link to comment
Share on other sites

  • Majd123mc changed the title to [CLOSED] [1.18.1] META-INF/libraries not working

@noSkill
 

8 hours ago, noSkill said:

So how to include dependencies?


You will have to create a fat jar instead.

A quick google search will show you plenty of results.

HOWEVER, in 1.18.1 ANY external dependencies, when debugging using the debug tool in IntelliJ, the libraries don't load AT ALL. Which has nothing to do with fat-jaring and is a *bug*.

But if you want to package other libraries in your mod, you will need to create a fat jar. I've found this resource to be useful: https://gist.github.com/Commoble/ddc75e819a690198c15d26564d139333

*P.S. I was not able to test if the Jar-in-Jar method works still, it MAY work in 1.18.1 but I cannot verify that because of the bug. There is a chance it still works so you can test it out and if it works for you, great! If it doesn't, then use the fat jar method instead.*

Link to comment
Share on other sites

Shadow plugin didn't work for me. It gave some errors on launch saying that my module both requires and exports the same packages. My current approach is to add only certain dependencies manually:
 

dependencies {

minecraft 'net.minecraftforge:forge:1.18.1-39.0.59'

        jar { from { configurations.compileClasspath.findAll { (it.name.endsWith('jar') && !it.name.contains('forge')) }.collect {  zipTree(it) } }

}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.