Jump to content

Gradle noob needs help with dependencies


Chekote

Recommended Posts

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

Link to comment
Share on other sites

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 >.<

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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 by MDW01
  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.