java - NoSuchMethodError 使用 maven
问题描述
当我运行我的 jar 时,它会引发异常。我反编译了jar,发现方法存在。我尝试在我自己的 pom 中添加 Gson 和改造依赖项,但没有成功。我错过了什么?
java.lang.NoSuchMethodError: com.google.gson.Gson.newJsonReader(Ljava/io/Reader;)Lcom/google/gson/stream/JsonReader;
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:38) ~[?:?]
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27) ~[?:?]
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243) ~[?:?]
at retrofit2.OkHttpCall.execute(OkHttpCall.java:204) ~[?:?]
at com.jaredsburrows.retrofit2.adapter.synchronous.SynchronousBodyCallAdapter.adapt(SynchronousBodyCallAdapter.java:27) ~[?:?]
我已经阅读了无数关于相同/相似问题的线程,但没有一个有助于解决这个问题。这是我现在的pom:
...
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.theminecoder</groupId>
<artifactId>agones-java-sdk</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/</exclude>
</excludes>
</filter>
</filters>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Maven 依赖:树输出:
[INFO] com.mycompany:artifact:jar:1.0-SNAPSHOT
[INFO] +- org.spigotmc:spigot:jar:1.8.8-R0.1-SNAPSHOT:provided
[INFO] \- com.github.theminecoder:agones-java-sdk:jar:1.0.2:compile
[INFO] +- com.squareup.retrofit2:retrofit:jar:2.8.2:compile
[INFO] | \- com.squareup.okhttp3:okhttp:jar:3.14.9:compile
[INFO] | \- com.squareup.okio:okio:jar:1.17.2:compile
[INFO] +- com.jaredsburrows.retrofit:retrofit2-synchronousadapter:jar:0.5.0:compile
[INFO] \- com.squareup.retrofit2:converter-gson:jar:2.8.2:compile
[INFO] \- com.google.code.gson:gson:jar:2.8.5:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
解决方案
推荐阅读
- python - 尝试从 django 中的基表中过滤日期字段时出现名称错误
- sql - 使用分区上的过滤器值查询同一张表
- android - 如何在android studio中有效地使用OpenCV调整图像亮度
- android - 打开应用程序时停止 Workmanager 颤动
- ios - 在垂直堆栈视图中具有自动项目大小的水平分页 UICollectionView?
- php - Stripe 资金不足:重定向到新页面
- javascript - CHAKRA-UI:如何用一个道具显示多个道具样式值?
- javascript - 订单确认后如何从订购数量中减去可用数量?
- lua - 如何在 R Markdown 中将两个单独的 lua 过滤器应用于 Span 元素?
- awk - 哪个 AWK 程序可以进行这种操作?