Jump to content

GSON java.lang.NoSuchMethodError


Fxy

Recommended Posts

Hello im trying to make a mod and the past few days GSON has almost killed me, when i export the mod and then launch it through minecraft launcher i get

java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseString(Ljava/lang/String;)Lcom/google/gson/JsonElement;

i have literally tried everything here is my build config
 

dependencies {
    minecraft("com.mojang:minecraft:1.8.9")
    mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9")
    forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9")

    compileOnly("cc.polyfrost:oneconfig-1.8.9-forge:0.2.2-alpha+")
    shadowImpl("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") {
        isTransitive = false
        exclude(module = "gson")
    }

    shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
        isTransitive = false
        exclude(module = "gson")
    }
    annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT")

    shadowImpl("org.javassist:javassist:3.15.0-GA") {
        isTransitive = false
        exclude(module = "gson")
    }
    shadowImpl("com.neovisionaries:nv-i18n:1.28") {
        isTransitive = false
        exclude(module = "gson")
    }

    shadowImpl("org.apache.commons:commons-lang3:3.4") {
        isTransitive = false
        exclude(module = "gson")
    }
    shadowImpl("org.apache.httpcomponents:httpcore:4.4.5") {
        isTransitive = false
        exclude(module = "gson")
    }

    compileOnly("com.google.code.gson:gson:2.8.6") { isTransitive = false }

    configurations.all { resolutionStrategy { force("com.google.code.gson:gson:2.8.6") } }
    shadowImpl(fileTree(
        mapOf(
            "dir" to "libs",
            "include" to listOf("*.jar"),
            "exclude" to listOf(
                "asm",
                "asm-commons",
                "asm-tree",
                "gson",
                "unspecified",
                "nv-i18n"
            )
        )
    ))
}

 

Link to comment
Share on other sites

The conflict arises from discrepancies between different versions of GSON.


My suggestion would be to remove your dependency on GSON 2.8.6 and opt for a different approach. Instead of using the static method JsonParser.parseString, you can create a JsonParser object and then use the parse method.

 

JsonParser jsonParser = new JsonParser();
jsonParser.parse(jsonString)

 

Edited by bluedisgusted
-
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.



×
×
  • Create New...

Important Information

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