Hello, I am working on a mod and I am using a custom dependency. I added the jar files according to the docs and used a build.gradle based on PaleoCrafter.
If I open the jar file I can see all of the .meta and .jar files and I can also see forge extracting them into the mods/1.12.2 folder. But when the game is launched the mod crashes during initialization due to
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
It runs fine in intellij
This is my build.gradle:
buildscript {
repositories {
jcenter()
maven { url = "https://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
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.suppergerrie2.dependencytest"
archivesBaseName = "sdependencytest"
repositories {
mavenLocal()
}
sourceCompatibility = targetCompatibility = '1.8'
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
minecraft {
version = "1.12.2-14.23.5.2814"
runDir = "run"
mappings = "stable_39"
}
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version':project.version, 'mcversion':project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
//From https://github.com/PaleoCrafter/Dependency-Extraction-Example/blob/library-embedding/build.gradle
configurations {
// Configuration that holds JARs to embed inside the mod JAR
embed
// Make embedded dependencies actually available during compilation/to IDEs
compile.extendsFrom embed
}
dependencies {
embed group: 'com.schematical.chaosnet', name: 'ChaosNet', version: '1.0-SNAPSHOT'
}
// Custom task to generate the metadata files required for our dependencies
task generateMetaFiles {
// Code for execution after the whole buildscript was parsed and loaded
doLast {
// Clear the dependencyMeta directory since we don't want old dependencies to still be listed in there
file("${buildDir}/dependencyMeta/").deleteDir()
configurations.embed.resolvedConfiguration.resolvedArtifacts.each {
// Create a meta file for each dependency in a specified directory
def metaFile = file("${buildDir}/dependencyMeta/${it.file.name}.meta")
metaFile.parentFile.mkdirs()
// Use the Gradle notation provided by the API ('group:artifact:version') for the meta file...
def artifactRef = it.moduleVersion.toString()
// ...and append the classifier if present
if (it.classifier != null) {
artifactRef += ":${it.classifier}"
}
// Write the artifact information to the meta file, to be used by the
metaFile.text = "Maven-Artifact: $artifactRef"
}
}
}
// Use the standard JAR task as container for the main jar and the contained dependencies (from the embed configuration)
jar {
into('/META-INF/libraries/') {
// Add all of the dependency JARs to the main JAR for later extraction
from configurations.embed
// Also include all dependency meta files
from "${buildDir}/dependencyMeta/"
}
manifest {
// The crucial manifest attribute: Make Forge extract the contained JARs
attributes 'ContainedDeps': configurations.embed.collect { it.name }.join(' ')
}
// Only run the main jar task after the meta files were built
dependsOn generateMetaFiles
}
And this is the only class in the mod:
package com.suppergerrie2.dependencytest;
import com.schematical.chaosnet.ChaosNet;
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.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;
@Mod(modid = TestMod.MODID, name = TestMod.NAME, version = TestMod.VERSION)
public class TestMod {
public static final String MODID = "sdependencytest";
public static final String NAME = "Test Mod";
public static final String VERSION = "1.0";
private static Logger logger;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
ChaosNet sdk = ChaosNet.builder()
.build();
logger.info(sdk);
}
@EventHandler
public void init(FMLInitializationEvent event) {
}
}