TheRandomLabs / CurseAPI

A Java library for handling interactions with CurseForge.
MIT License
30 stars 3 forks source link

slf4j/LoggerFactory NoClassDefFoundError when using CurseAPI in a mod #35

Closed ROMVoid95 closed 2 years ago

ROMVoid95 commented 4 years ago

So i had the idea of using this in my mod to assist in the downloading of mod updates for players. While in the Dev environment it works without fail, however when its built and loaded in a modpack when the download task is called it receives a NoClassDefFoundError and does not perform

[10:53:34] [Client thread/INFO]: [CHAT] Hey player! Hey player hey! GalacticTweaks update!
[10:53:34] [Client thread/INFO]: [CHAT] §6****************************************
[10:53:34] [Client thread/INFO]: [CHAT] §6* §aRunning......v§c1.1.0
[10:53:34] [Client thread/INFO]: [CHAT] §6* §aLatest.........v§91.2.0
[10:53:34] [Client thread/INFO]: [CHAT] §6****************************************
[10:53:34] [Client thread/INFO]: [CHAT] Click To... [Download]
[10:53:34] [Client thread/INFO]: Loaded 3 advancements
[10:53:38] [Server thread/WARN]: Couldn't process command: download-latest-gctweaks 3032603
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.therandomlabs.curseapi.CurseAPI.<clinit>(CurseAPI.java:100) ~[CurseAPI.class:1.1.0]
    at net.rom.gctweaks.base.version.DownloadUpdate.<init>(DownloadUpdate.java:28) ~[DownloadUpdate.class:1.1.0]
    at net.rom.gctweaks.base.version.CommandDownloadUpdate.func_184881_a(CommandDownloadUpdate.java:41) ~[CommandDownloadUpdate.class:1.1.0]
    at net.minecraft.command.CommandHandler.func_175786_a(CommandHandler.java:119) [bj.class:?]
    at net.minecraft.command.CommandHandler.func_71556_a(CommandHandler.java:91) [bj.class:?]
    at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:962) [pa.class:?]
    at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:941) [pa.class:?]
    at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:37) [la.class:?]
    at net.minecraft.network.play.client.CPacketChatMessage.func_148833_a(SourceFile:9) [la.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) [hv$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_51]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_51]
    at net.minecraft.util.Util.func_181617_a(SourceFile:46) [h.class:?]
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:723) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:185) [chd.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_51]
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:101) ~[launchwrapper-1.12.jar:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_51]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_51]
    ... 18 more
[10:53:38] [Client thread/INFO]: [CHAT] An unknown error occurred while attempting to perform this command

in the build file the dependency is defined ad

embed("com.github.TheRandomLabs:CurseAPI:master-SNAPSHOT"){
    exclude group: 'com.google.guava', module: 'guava'
    }

its configured to be included in the mod and the guava had to be excluded as it just wouldn't work with it.

any idea on this one?

TheRandomLabs commented 4 years ago

SLF4J will have to be shadowed into the mod jar. I'm not altogether proficient with Gradle myself, but maybe try manually embedding org.slf4j:slf4j-api:2.0.0-alpha1?

TheRandomLabs commented 4 years ago

Let me know if this is still a problem.

ROMVoid95 commented 4 years ago

Sorry for not following up on this, it currently still happens. I had cloned the repo to try and find the solution but real life caught up lol.

ROMVoid95 commented 3 years ago

~After coming back to this issue after a long while, the issue that I ran into is simply due to myself not shadowing the transitive dependencies that the API requires and them not being present in any FML environment. So your free to close this.~

ROMVoid95 commented 3 years ago

When this is used in a mod, the logger (slf4j) is not packed when built. Of course this is (and in my opinion should be the case) by design and its up to the end-user to handle the logging dependency and Forge and Minecraft both use Log4j2, not slf4j. So the original issue I ran into from the start is not applicable as being an issue with the library.