Posted August 3, 20169 yr Heya, I'm having dependency troubles during mod loading. I have a set of dependencies including slf4j, and the mod is not finding them during load. It functions correctly in the development environment, and builds correctly, but as soon as I try to run the mod from forge, the dependency is not found. Here is the relevant section of my build file: dependencies { //both added as an effort to overcome the problem. embed ('org.slf4j:slf4j-api:1.7.5') embed ('org.slf4j:jcl-over-slf4j:1.7.12') //other dependencies } Here is the error I'm getting: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at org.drools.compiler.kie.builder.impl.KieContainerImpl.<clinit>(KieContainerImpl.java:84) ~[KieContainerImpl.class:?] at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieClasspathContainer(KieServicesImpl.java:99) ~[KieServicesImpl.class:?] at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:82) ~[KieServicesImpl.class:?] at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:73) ~[KieServicesImpl.class:?] at org.drools.game.core.GameSessionImpl.bootstrap(GameSessionImpl.java:92) ~[GameSessionImpl.class:?] at org.drools.minecraft.adapter.NewAdapter.bootstrapWorld(NewAdapter.java:83) ~[NewAdapter.class:?] at org.drools.minecraft.adapter.NewAdapter.<init>(NewAdapter.java:59) ~[NewAdapter.class:?] at org.drools.minecraft.adapter.NewAdapter.<clinit>(NewAdapter.java:43) ~[NewAdapter.class:?] at com.example.droolsinterface.InitCommon.preInit(InitCommon.java:29) ~[initCommon.class:?] at com.example.examplemod.ExampleMod.preInit(ExampleMod.java:23) ~[ExampleMod.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:566) ~[forge-1.9.4-12.17.0.1976.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?] at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228) ~[forge-1.9.4-12.17.0.1976.jar:?] at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206) ~[forge-1.9.4-12.17.0.1976.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?] at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135) [LoadController.class:?] at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:586) [Loader.class:?] at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249) [FMLClientHandler.class:?] at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:437) [bcd.class:?] at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:349) [bcd.class:?] at net.minecraft.client.main.Main.main(SourceFile:124) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] 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_25] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_25] ... 47 more [10:18:07] [Client thread/INFO] [sTDOUT/]: [net.minecraft.init.Bootstrap:func_179870_a:560]: ---- Minecraft Crash Report ---- // Surprise! Haha. Well, this is awkward. Time: 8/3/16 10:18 AM Description: There was a severe problem during mod loading that has caused the game to fail net.minecraftforge.fml.common.LoaderException: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at net.minecraftforge.fml.common.LoadController.transition(LoadController.java:179) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:589) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249) at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:437) at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:349) at net.minecraft.client.main.Main.main(SourceFile:124) 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.NoClassDefFoundError: org/slf4j/LoggerFactory at org.drools.compiler.kie.builder.impl.KieContainerImpl.<clinit>(KieContainerImpl.java:84) at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieClasspathContainer(KieServicesImpl.java:99) at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:82) at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:73) at org.drools.game.core.GameSessionImpl.bootstrap(GameSessionImpl.java:92) at org.drools.minecraft.adapter.NewAdapter.bootstrapWorld(NewAdapter.java:83) at org.drools.minecraft.adapter.NewAdapter.<init>(NewAdapter.java:59) at org.drools.minecraft.adapter.NewAdapter.<clinit>(NewAdapter.java:43) at com.example.droolsinterface.InitCommon.preInit(InitCommon.java:29) at com.example.examplemod.ExampleMod.preInit(ExampleMod.java:23) 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:566) 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.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206) 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.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:586) ... 10 more Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:101) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 47 more I also tried adding { "name": "org.slf4j:slf4j-api:1.7.2”, "url": "http://files.minecraftforge.net/maven/" } to the "libraries" section in minecraft's configuration files, for my version of Forge. This didn't work, either. Any ideas how to effectively add dependencies?
August 4, 20169 yr Author Is there any alternative for shaded (/fat) jars? In our case, the main problem of shaded jars is that we have serveral META-INF/ files in different jars that overlaps each other, and we will need to create a way to merge these files for the shaded approach. It will be interesting to know if there is a way to define the classpath of the mod in a different way, such a libs directory or a mod specific configuration file to define which dependencies needs to be picked up. Also for the org.slf4j.LoggerFactory issue, we can see the class being bundled inside the shaded jar, but for some reason minecraft is not picking it up. Is there any Classloader magic happening for mods?
August 4, 20169 yr Author There isn't an alternative, sadly. I wish we had some kind of maven resolution for mods either in the launcher or in forge startup, but alas that comes with a lot of security concerns. Thanks, this is something I very much needed to know. Do you have any idea what could cause the problem in my first post, where built-in dependencies were not being found? At this point, even a general "well, you might look *here*, but I really don't know" would be massively useful.
August 4, 20169 yr Author I have a couple gradle files. (was trying some things, and they got kind of stretched out.) /* root project build.gradle */ import org.gradle.api.artifacts.* apply plugin: 'base' // To add "clean" task to the root project. subprojects { apply from: rootProject.file('common.gradle') } task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') { title = 'All modules' destinationDir = new File(project.buildDir, 'merged-javadoc') // Note: The closures below are executed lazily. source { subprojects*.sourceSets*.main*.allSource } classpath.from { subprojects*.configurations*.compile*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve() } } /* root project common.gradle */ // // This file is to be applied to every subproject. // apply plugin: 'java' apply plugin: 'maven' String mavenGroupId = 'org.drools.minecraft' String mavenVersion = '1.0-SNAPSHOT' sourceCompatibility = '1.8' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' repositories { mavenCentral(); // You may define additional repositories, or even remove "mavenCentral()". // Read more about repositories here: // http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories } dependencies { // Adding dependencies here will add the dependencies to each subproject. testCompile group: 'junit', name: 'junit', version: '4.10' } String mavenArtifactId = name group = mavenGroupId version = mavenVersion task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from the source files.') { classifier = 'sources' from sourceSets.main.allSource } artifacts { archives jar archives sourcesJar } configure(install.repositories.mavenInstaller) { pom.project { groupId = mavenGroupId artifactId = mavenArtifactId version = mavenVersion } } task createFolders(description: 'Creates the source folders if they do not exist.') doLast { sourceSets*.allSource*.srcDirs*.each { File srcDir -> if (!srcDir.isDirectory()) { println "Creating source folder: ${srcDir}" srcDir.mkdirs() } } } /* Root project settings.gradle */ rootProject.name = 'minecraft-drools-game' // Find the directories containing a "build.gradle" file in the root directory // of the project. That is, every directory containing a "build.gradle" will // be automatically the subproject of this project. def subDirs = rootDir.listFiles(new FileFilter() { public boolean accept(File file) { if (!file.isDirectory()) { return false } if (file.name == 'buildSrc') { return false } return new File(file, 'build.gradle').isFile() } }); subDirs.each { File dir -> include dir.name } /* mod build.gradle */ // For those who want the bleeding edge buildscript { repositories { jcenter() maven { name = "forge" url = "http://files.minecraftforge.net/maven" } } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' } } apply plugin: 'net.minecraftforge.gradle.forge' /* // for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot plugins { id "net.minecraftforge.gradle.forge" version "2.0.2" } */ version = "1.0" group= "org.drools.minecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "minecraft-drools-game" configurations { embed compile.extendsFrom(embed) } minecraft { version = "1.9.4-12.17.0.1976" 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 allways work. // simply re-run your setup task after changing the mappings to update your workspace. mappings = "snapshot_20160518" // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } repositories { mavenLocal() maven{ name = "jboss" url = "https://repository.jboss.org/nexus/content/groups/public-jboss" } } dependencies { embed ('org.slf4j:slf4j-api:1.7.5') embed ('org.slf4j:jcl-over-slf4j:1.7.12') embed ('org.drools.game:drools-game-engine-core-impl:1.0-SNAPSHOT'){ exclude group: 'commons-io', module: 'commons-io' transitive = true } embed ('org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'){ exclude group: 'commons-io', module: 'commons-io' transitive = true } runtime 'org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT' } 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, thats not the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } } jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) } }
August 5, 20169 yr Author I tried shifting over to the shadow plugin, and while it does a very nice job of putting all the dependencies together, It produces a .zip file that is not recognized by minecraft as a mod. Do you know any tricks to either make it produce a compatible .jar, or get minecraft to recognize the zip? (the new build.gradle): // For those who want the bleeding edge buildscript { repositories { jcenter() maven { name = "forge" url = "http://files.minecraftforge.net/maven" } } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' } dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' } } apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'application' /* // for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot plugins { id "net.minecraftforge.gradle.forge" version "2.0.2" } */ version = "1.0" group= "org.drools.minecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "minecraft-drools-game" mainClassName='com.example.examplemod.ExampleMod' minecraft { version = "1.9.4-12.17.0.1976" 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 allways work. // simply re-run your setup task after changing the mappings to update your workspace. mappings = "snapshot_20160518" // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } repositories { mavenLocal() maven{ name = "jboss" url = "https://repository.jboss.org/nexus/content/groups/public-jboss" } } dependencies { compile ('org.drools.game:drools-game-engine-core-impl:1.0-SNAPSHOT'){ exclude group: 'commons-io', module: 'commons-io' transitive = true } compile ('org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'){ exclude group: 'commons-io', module: 'commons-io' transitive = true } runtime 'org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT' shadow ('org.drools.game:drools-game-engine-core-impl:1.0-SNAPSHOT'){ exclude group: 'commons-io', module: 'commons-io' exclude group: 'xmlpull', module: 'xmlpull' exclude group: 'org.slf4j', module: 'slf4j-api' transitive = true } shadow ('org.drools.game:drools-game-engine-horserace-kjar:1.0-SNAPSHOT'){ exclude group: 'xmlpull', module: 'xmlpull' exclude group: 'commons-io', module: 'commons-io' exclude group: 'org.slf4j', module: 'slf4j-api' transitive = true } } 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, thats not the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } } shadowJar { baseName = 'horse-race-fatjar' classifier = null version = null mergeServiceFiles() }
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.