我试图在我的程序中使用Unirest,但是我一直收到这个错误java.lang.NoSuchMethodError: com.google.gson.Gson.newBuilder()Lcom/google/gson/GsonBuilder;
我尝试过使用不同的maven版本的Gson,但我仍然继续使用这个seror
Edid添加了我的pom.xml,我试着删除了我的.m2,但是我仍然有这个问题
<dependencies>
<!-- https://mvnrepository.com/artifact/com.konghq/unirest-java -->
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.7.00</version>
<classifier>standalone</classifier>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>Spigot8</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/spigot-1.8.8-R0.1-SNAPSHOT-latest.jar</systemPath>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>compile</scope>
</dependency>
</dependencies>```发布于 2020-04-30 20:52:47
可能是POM文件中的GSON版本与容器(Tomcat/JBoss)中的版本之间存在冲突。如果有两个不同的版本,则删除与maven项目的POM文件中的当前版本不同的版本。我也遇到了类似的问题--我的项目使用的是gson-2.6.3.jar,但WEB-INF/lib中也存在冲突的gson-2.1.jar。我删除了gson-2.1.jar,这解决了我的问题
发布于 2020-04-03 12:04:21
此问题可能是由于Gson版本中的冲突造成的。
如果您在windows上,请转到您的存储库:
C:\Users\User_name.m2\repository\com\google\code\gson
或者在Mac上:
/.m2/repository/com/google/code/gson
删除所有现有文件夹。
现在,在pom文件中添加以下maven依赖项:
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>重新构建maven项目并尝试运行。
发布于 2020-04-03 12:25:35
这看起来像是一个依赖问题。
请确保您的依赖项是正确的。Unirest 3.7.00使用Gson 2.8.6
https://mvnrepository.com/artifact/com.konghq/unirest-java/3.7.00
此外,如果您不单独使用Gson,则不需要指定它。只需为unirest-java添加一个依赖项,就像Maven存储库中描述的那样:
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.7.00</version>
</dependency>https://stackoverflow.com/questions/61004801
复制相似问题