Jump to content

Having trouble shading with my mod


fernthedev
 Share

Recommended Posts

So basically I can run the mod just fine when I run the "runClient" task and everything works great. However, when I compile it with shadowJar it has all the libraries, yet when Minecraft loads it, it says it can't be found.

Here's the log

---- Minecraft Crash Report ----

WARNING: coremods are present:
Contact their authors BEFORE contacting forge

// Quite honestly, I wouldn't worry myself about that.

Time: 5/21/18 3:54 PM
Description: There was a severe problem during mod loading that has caused the game to fail

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Discord (discordmod)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/SystemUtils
	at net.arikia.dev.drpc.DiscordRPC.loadDLL(DiscordRPC.java:128)
	at net.arikia.dev.drpc.DiscordRPC.<clinit>(DiscordRPC.java:21)
	at com.github.fernthedev.DiscordMod.init(DiscordMod.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:600)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:278)
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:256)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:148)
	at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:720)
	at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:352)
	at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:534)
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:377)
	at net.minecraft.client.main.Main.main(SourceFile:123)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.SystemUtils
	at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:106)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 44 more

 

I have one library for discord rich presence found here (https://github.com/Vatuu/discord-rpc)

 

My build.gradle

buildscript {
    repositories {
        jcenter()
        maven { url = "http://files.minecraftforge.net/maven" }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
    }
}
plugins {
    id "com.github.johnrengelman.shadow" version "1.2.4"
}
apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.0"
group = "com.github.fernthedev" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "DiscordMod"

sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
    sourceCompatibility = targetCompatibility = '1.8'
}

configurations {
    shade
    compile.extendsFrom shade
}

shadowJar {
    baseName = project.name //+ '-all'
}

jar {
    configurations.shade.each { dep ->
        from(project.zipTree(dep)) {
            exclude 'META-INF', 'META-INF/**'
        }
    }
}
minecraft {
    version = "1.12.2-14.23.3.2702"
    runDir = "run"
    
    // the mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   snapshot are built nightly.
    // stable_#            stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not always work.
    // simply re-run your setup task after changing the mappings to update your workspace.
    mappings = "snapshot_20171003"
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
//        srgExtra "PK: org/ejml your/new/package/here/ejml"
 //       srgExtra "PK: org/ejml/alg your/new/package/here/ejml/alg"
}

//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'discordmod',
                'Implementation-Version': version,
                'Main-Class': 'com.github.fernthedev.DiscordMod'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

repositories {
    maven {
        name = 'Tethys (drakon.io)'
        url = "http://tethys.drakon.io/maven"
    }
}

dependencies {
    // you may put jars on which you depend on in ./libs
    // or you may define them like so..
    //compile "some.group:artifact:version:classifier"
    //compile "some.group:artifact:version"
    //compile 'com.jagrosh:DiscordIPC:LATEST'
    compile 'org.json:json:20171018'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
    compile 'io.drakon:pulsar:1.2.1'
//     shade fileTree(dir: 'libs', include: '*.jar')

    // real examples
    //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev'  // adds buildcraft to the dev env
    //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
}

processResources {
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'

        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }

    // copy everything else except the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

 

and my main class

package com.github.fernthedev;

import net.arikia.dev.drpc.DiscordEventHandlers;
import net.arikia.dev.drpc.DiscordRPC;
import net.minecraft.client.Minecraft;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLModDisabledEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;

@Mod(modid = DiscordMod.MODID, name = DiscordMod.NAME, version = DiscordMod.VERSION)
public class DiscordMod {
    public static final String MODID = "discordmod";
    public static final String NAME = "Discord";
    public static final String VERSION = "1.0";

    private static Logger logger;
    private RPC rpc;
    public static String client;
    private static DiscordMod instance;
    //private static IPCClient client;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        logger = event.getModLog();
    }



    @EventHandler
    public void init(FMLInitializationEvent event) {

        DiscordEventHandlers handler = new DiscordEventHandlers();
        instance = this;
        rpc = new RPC();
        new RPCEvents(rpc);

        handler.ready = new ReadyEvent();
        client = "448100612987551744L";
        DiscordRPC.discordInitialize(client, handler,true);

        IThreadListener mainThread = Minecraft.getMinecraft();
        mainThread.addScheduledTask(DiscordRPC::discordRunCallbacks);
    }

    @EventHandler
    public void loaded(FMLPostInitializationEvent e) {
        rpc.menu(client);
        MinecraftForge.EVENT_BUS.register(new RPCEvents(rpc));
    }

    @EventHandler
    public void shutdown(FMLModDisabledEvent e) {
        DiscordRPC.discordShutdown();
    }

    public static DiscordMod getInstance() {
        return instance;
    }

    public Logger logger() {
        return logger;
    }
}

 

I've tried using many ways of shading or making fat jars but they all keep saying the exact same error.

Link to comment
Share on other sites

Yea this can be a bit tricky. Personally, the way I would do it is by adding that repository to yours using a git submodule. This shouldn't be an issue since they have an MIT license just make sure to give them credit. It will then get compiled directly into your code. It is pretty easy to keep the library up to date using git modules and they make it even easier to change the library if you need to.

Link to comment
Share on other sites

2 hours ago, MDW01 said:

Yea this can be a bit tricky. Personally, the way I would do it is by adding that repository to yours using a git submodule. This shouldn't be an issue since they have an MIT license just make sure to give them credit. It will then get compiled directly into your code. It is pretty easy to keep the library up to date using git modules and they make it even easier to change the library if you need to.

So you're suggesting I add my project as github repository, adding which "repository" as a git submodule? Also I have given them credit in the mcmod.info file

[
{
  "modid": "discordmod",
  "name": "Discord",
  "description": "Enables Rich Presence For your profile.",
  "version": "1.0",
  "mcversion": "${mcversion}",
  "url": "",
  "updateUrl": "",
  "authorList": ["Fernthedev"],
  "credits": "jagrosh for discord api. https://github.com/jagrosh/DiscordIPC",
  "logoFile": "",
  "screenshots": [],
  "dependencies": []
}
]

 

Edit:

this error keeps appearing no matter what way I fatjar/shade it, and I opened it with winrar and it does exist inside it

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/SystemUtils
Quote

 

 
Quote

 

 

 

Edited by fernthedev
another reason
Link to comment
Share on other sites

I’m pretty new to using gradle (I used maven and did plugin development back then) and never had to shade

7 hours ago, diesieben07 said:

What?!

 

@fernthedev Mods cannot contain code in the org.apache package. You must relocate the repackaged code to somewhere else.

So what I understand from this is I have to download the library and add it locally with a different name?

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

I've been using that and org.apache.lang.systemutils is included inside it but Minecraft keeps showing the error it's not showing

Quote

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/SystemUtils
 

I've also tried other methods of fat jar-ing it and it still causes the exact error. This is being thrown because the library I'm using for the discord API is using that class (I compiled the app myself and it does indeed have the maven shading plugin in the pom.xml and is included)

Extract the jar and see for yourself what I'm dealing with.

https://www.dropbox.com/s/qsfsdzoa7ent06v/DiscordMod-1.0-all.jar?dl=0

Link to comment
Share on other sites

26 minutes ago, diesieben07 said:

You need to change the package, not just include the dependency.

Like I said, mods cannot contain code in the org.apache package.

Actually now I'm receiving this error. I added logger to gradle but still.

Caused by: java.lang.NoClassDefFoundError: shadow/org/apache/logging/log4j/Logger

Jar with the relocated package

https://www.dropbox.com/s/qsfsdzoa7ent06v/DiscordMod-1.0-all.jar?dl=0

Link to comment
Share on other sites

Actually nevermind, I fixed that last issue with relocating. However, this issue is very odd.

---- Minecraft Crash Report ----

WARNING: coremods are present:
Contact their authors BEFORE contacting forge

// I let you down. Sorry :(

Time: 5/22/18 2:15 PM
Description: There was a severe problem during mod loading that has caused the game to fail

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Discord (discordmod)
Caused by: java.lang.NoSuchMethodError: net.minecraft.client.Minecraft.getMinecraft()Lnet/minecraft/client/Minecraft;
	at com.github.fernthedev.DiscordMod.init(DiscordMod.java:48)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:627)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:218)
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:196)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135)
	at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:744)
	at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:329)
	at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:534)
	at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:377)
	at net.minecraft.client.main.Main.main(SourceFile:123)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

https://www.dropbox.com/s/qsfsdzoa7ent06v/DiscordMod-1.0-all.jar?dl=0

Edited by fernthedev
link
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
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.

 Share



×
×
  • Create New...

Important Information

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