Chekote Posted September 21, 2017 Posted September 21, 2017 Hi everyone! I just introduced javax.json as a dependency to my project, and I'm having mixed success getting the compiled jar to work. I've managed to get the dependency working with Forge 1.7.10-10.13.4.1614-1.7.10 by configuring Gradle to compile the dependency into the jar: Spoiler buildscript { repositories { mavenCentral() maven { name = "forge" url = "http://files.minecraftforge.net/maven" } maven { name = "sonatype" url = "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' } } apply plugin: 'forge' version = "1.3.0" group= "com.monkeyinabucket.forge.blink" archivesBaseName = "blink" minecraft { version = "1.7.10-10.13.4.1614-1.7.10" runDir = "eclipse" } configurations { embed compile.extendsFrom(embed) } dependencies { embed( [group: 'javax.json', name: 'javax.json-api', version: '1.0'], [group: 'org.glassfish', name: 'javax.json', version: '1.0.4'] ) } jar { // exclude Photoshop files exclude '**/*.psd' from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) } } 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' } } This works (but I'd still be interested on feedback as to whether this is the correct approach). However, when I try to do the same thing with Forge 1.8.9-11.15.1.1722, then I have the following problems: * When I build the project with the dependencies declared in the "embed" section, I get the following error from gradle: "java.util.zip.ZipException: duplicate entry: javax/json/Json.class". * When I change the "embed" section to "compile" so that the dependency is not added to the jar, then I get a class not found error when I try to load the jar into minecraft. I am really confused as to what's going on. If the javax.json dependency is already being build into the jar by Forge Gradle, then why is the class missing when I try to run the mod in minecraft? I thought maybe there might be a version mismatch between the javax.json that I'm using and what I assume Forge Gradle is adding to the jar, but I don't know how to determine if that's the case. Please help. I've exhausted my limited knowledge! Thanks in advance, - Chekote Quote
MDW01 Posted September 21, 2017 Posted September 21, 2017 Here is a post you might find helpful. https://stackoverflow.com/questions/3445825/gradle-how-do-i-build-a-jar-with-a-lib-dir-with-other-jars-in-it Quote
Chekote Posted September 21, 2017 Author Posted September 21, 2017 Hi MDW01, Thanks so much for the reply! The post you linked seems to be how to get the dependency into the Jar. I've already successfully done that. My problem is that with MC 1.8.9, Gradle won't add the dependency to the jar without complaining of a conflict, but if I don't add it to the jar, then Minecraft complains that the classes are missing when it tries to run the mod. How can there both be a conflict, and yet the classes be missing if I don't add them? It doesn't make sense to me >.< Quote
MDW01 Posted September 21, 2017 Posted September 21, 2017 May I ask what you are using Javax for? Quote
Chekote Posted September 22, 2017 Author Posted September 22, 2017 (edited) I'm using it to serialize the position and configuration of structures within the game world to JSON. Edited September 22, 2017 by Chekote Quote
MDW01 Posted September 22, 2017 Posted September 22, 2017 If your just using it to read and write data to JSON I would recommend using GSON instead of javax. I also believe it is included in the forge libraries so you don't have to add javax to your jar. Quote
Chekote Posted September 22, 2017 Author Posted September 22, 2017 OK, I'll look into that. I would still like to know what the cause and fix to my original issues is though. It's only a matter of time before I need to include something else as a dependency. Quote
Chekote Posted September 22, 2017 Author Posted September 22, 2017 @MDW01 I'm curious: How did you know that GSON is part of Forge? I'm curious because I was trying to find out if there was a JSON library already in Forge when I started to write the feature, but couldn't work out how I would determine that. I only write Java as a hobby, so I'm not very familiar with the ecosystem or tools. Quote
MDW01 Posted September 22, 2017 Posted September 22, 2017 (edited) I wouldn't worry about trying to figure out how to add dependencies to your jar almost everything you'll need is already included in the forge and Minecraft libraries. Look through the libraries in your workspace and you'll see what forge gradle has added to your workspace also you can look through Minecafts source code to get ideas on how mojang implements stuff and if you view the forge source you can get information on how to use the forge code. Edited September 22, 2017 by MDW01 1 Quote
Recommended Posts
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.