Issue using gson in gradle plugin

I am indirectly importing gson in a gradle plugin. I check the dependencies and everywhere I am using the same version of gson: 2.10.1 (the latest at the time of writing).

Yet, when I use my plugin I get the infamous exception:

java.lang.NoSuchMethodError: 'com.google.gson.JsonElement com.google.gson.internal.Streams.parse(com.google.gson.stream.JsonReader)'

I suppose that gradle is coming with its own version of gson and that it is quite old. Am I right? Any idea on how to solve this?

Unless you use an ancient Gradle version, probably not.
That method is there since gson 2.4, that means since Gradle 3.1 the method should be in the built-in gson:

$ find ~/.gradle/wrapper/dists/ -type f -name '*gson*' | cut -d / -f 9- | grep -v http-client
gradle-1.12/lib/plugins/gson-2.2.4.jar
gradle-2.1/lib/plugins/gson-2.2.4.jar
gradle-2.1/lib/plugins/gson-2.2.4.jar
gradle-2.11/lib/plugins/gson-2.2.4.jar
gradle-2.12/lib/plugins/gson-2.2.4.jar
gradle-2.13/lib/plugins/gson-2.2.4.jar
gradle-2.14.1/lib/plugins/gson-2.2.4.jar
gradle-2.2/lib/plugins/gson-2.2.4.jar
gradle-2.8/lib/plugins/gson-2.2.4.jar
gradle-3.0/lib/plugins/gson-2.2.4.jar
gradle-3.1/lib/plugins/gson-2.7.jar
gradle-3.2.1/lib/plugins/gson-2.7.jar
gradle-5.6.2/lib/plugins/gson-2.8.5.jar
gradle-5.6.4/lib/plugins/gson-2.8.5.jar
gradle-6.0/lib/plugins/gson-2.8.5.jar
gradle-6.9/lib/plugins/gson-2.8.5.jar
gradle-6.9.3/lib/plugins/gson-2.8.5.jar
gradle-7.3.2/lib/plugins/gson-2.8.6.jar
gradle-7.4.2/lib/plugins/gson-2.8.6.jar
gradle-7.5.1/lib/plugins/gson-2.8.9.jar
gradle-7.6.1/lib/plugins/gson-2.8.9.jar
gradle-8.0/lib/plugins/gson-2.8.9.jar
gradle-8.0.2/lib/plugins/gson-2.8.9.jar
gradle-8.1/lib/plugins/gson-2.8.9.jar
gradle-8.1.1/lib/plugins/gson-2.8.9.jar

That is strange, as I am using gradle 8.1.1

Can you share a build --scan?
Maybe it can shed some light.

I solved the problem by taking a dependency (which is using gson 2.10.1) and changing it to produce a fat jar with gson relocated.

However this is the scan, maybe the problem can be uncovered and I can avoid building the fatJar with relocation for that dependency, as it is a bit awkward.

https://scans.gradle.com/s/joygcg4hahqtc

as it is a bit awkward

that are fat jars always :smiley:

That build scan is not of the failing build.
Can you share that of the failing build?
Or as it seems this is about FOSS work, maybe you can even share the failing project.