Reputation: 1
I download MDK from https://files.minecraftforge.net/net/minecraftforge/forge/index_1.16.5.html After building my forge mod in .jar and starting the minecraft, it gives me an error that the dependency was not found.
In the minecraft log the following is written:
java.lang.NoClassDefFoundError: org/json/simple/parser/JSONParser
at com.example.examplemod.JsonUtil.getConfig(JsonUtil.java:14)
In the build.gradlew file i have next dependecies:
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
}
But if I run minecraft with use runClient (from Intellij IDE), dependencies are successful installed, and my mod is work.
Full build.gradlew file content:
plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
}
version = mod_version
group = mod_group_id
base {
archivesName = mod_id
}
// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {
mappings channel: mapping_channel, version: mapping_version
copyIdeResources = true
runs {
// applies to all the run configs below
configureEach {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods {
"${mod_id}" {
source sourceSets.main
}
}
}
client {
// this block needs to be here for runClient to exist
}
server {
args '--nogui'
}
data {
// example of overriding the workingDirectory set in configureEach above
workingDirectory project.file('run-data')
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
}
}
}
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
repositories {
}
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
}
tasks.named('processResources', ProcessResources).configure {
var replaceProperties = [
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
forge_version: forge_version, forge_version_range: forge_version_range,
loader_version_range: loader_version_range,
mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
mod_authors: mod_authors, mod_description: mod_description,
]
inputs.properties replaceProperties
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand replaceProperties + [project: project]
}
}
tasks.named('jar', Jar).configure {
manifest {
attributes([
'Specification-Title' : mod_id,
'Specification-Vendor' : mod_authors,
'Specification-Version' : '1', // We are version 1 of ourselves
'Implementation-Title' : project.name,
'Implementation-Version' : project.jar.archiveVersion,
'Implementation-Vendor' : mod_authors,
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
finalizedBy 'reobfJar'
}
//tasks.named('publish').configure {
// dependsOn 'reobfJar'
//}
publishing {
publications {
register('mavenJava', MavenPublication) {
artifact jar
}
}
repositories {
maven {
url "file://${project.projectDir}/mcmodsrepo"
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
I tried use shadow plugin for Gradlew, but i did not understand how to install it correctly. Also, i tried change dependencies as follows: (Instead of implementation write minecraftLibrary)
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
minecraftLibrary 'com.googlecode.json-simple:json-simple:1.1.1'
}
But it does not work.
And i tried write implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' But that doesn't work.
Upvotes: 0
Views: 136
Reputation: 1
I had a similar problem with json-simple/non-minecarft dependency for mod i recently developed for minecraft 1.20.1, java 17, forge 47.3.1 with ForgeGradle 6 and gradle 8.8. i successfully solved it by doing this 2 steps. Even thought you are using gradlew, i think it should be able to work in your case too as gradlew use gradle.
first step should make your mod find this dependency when running runClient task.
in build.gradle(w) file:
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
minecraftLibrary fg.deobf("com.googlecode.json-simple:json-simple:1.1.1")
}
you would want to usefg.deobf() to ensures the dependency is found in runtime.
second step is to make your jar file to contain the dependencies in order for your mod to find them outside development environment (like curseforge in my case). using this thread, i learned there are 2 ways for this: jar-in-jar or shadowjar, and there are in that thread links to helpful guides to implement them. I didn't understand the jar-in-jar way but implementing shadowjar as the tutorial there explained, worked for me.
Upvotes: 0