使用Maven Shade插件时遇java.lang.NoSuchMethodError问题求助
问题:Velocity插件Maven Shade打包后出现Guava方法缺失及类找不到错误
我开发了一款VelocityPowered代理插件,功能是在玩家连接代理时启动Google Compute Engine实例。代码作为独立程序运行正常,但使用Maven Shade打包后出现如下错误:
java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap$Builder.buildKeepingLast()'
我的pom文件配置如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>de.kastenklicker</groupId> <artifactId>ActivateServer</artifactId> <version>0.0.1</version> <name>activateServer</name> <url>http://maven.apache.org</url> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <repositories> <repository> <id>papermc</id> <url>https://repo.papermc.io/repository/maven-public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.velocitypowered</groupId> <artifactId>velocity-api</artifactId> <version>3.2.0-SNAPSHOT</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.github.t9t.minecraft-rcon-client</groupId> <artifactId>minecraft-rcon-client</artifactId> <version>1.0.0</version> <scope>compile</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-compute --> <dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-compute</artifactId> <version>1.33.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.5.0</version> <configuration> <relocations> <relocation> <pattern>com.github.t9t.minecraft-rcon-client</pattern> <shadedPattern>de.kastenklicker.activeserver.com.github.t9t.minecraft-rcon-client</shadedPattern> </relocation> <relocation> <pattern>com.google.cloud</pattern> <shadedPattern>de.kastenklicker.activeserver.com.google.cloud</shadedPattern> </relocation> </relocations> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
我已尝试以下方法:
- 添加Google Guava依赖(参考相关问题)
- 手动配置打包时包含
com.google.common.collect.ImmutableMap类,但出现新错误:
java.lang.NoClassDefFoundError: com/google/auth/Credentials
添加com.google.auth.Credentials类的包含配置后也无效果。
恳请提供解决方案,谢谢!
内容的提问来源于stack exchange,提问作者KastenKlicker
相关产品推荐
相关产品推荐

