Minecraft插件JDA库与Kotlin版本冲突导致加载异常求助
问题
开发基于JDA库的Minecraft插件时,遭遇JDA集成的Kotlin库与SimpleCloud-Permissions插件的Kotlin版本冲突,具体报错信息如下:
07:42:24 [WARNING] Exception encountered when loading plugin: SimpleCloud-Permissions java.lang.LinkageError: loader constraint violation: when resolving interface method 'eu.thesimplecloud.clientserverapi.lib.promise.ICommunicationPromise eu.thesimplecloud.clientserverapi.lib.promise.ICommunicationPromise.then(kotlin.jvm.functions.Function1)' the class loader net.md_5.bungee.api.plugin.PluginClassloader @5ce8d869 of the current class, eu/thesimplecloud/module/permission/PermissionPool, and the class loader net.md_5.bungee.api.plugin.PluginClassloader @5460cf3a for the method's defining class, eu/thesimplecloud/clientserverapi/lib/promise/ICommunicationPromise, have different Class objects for the type kotlin/jvm/functions/Function1 used in the signature (eu.thesimplecloud.module.permission.PermissionPool is in unnamed module of loader net.md_5.bungee.api.plugin.PluginClassloader @5ce8d869, parent loader 'app'; eu.thesimplecloud.clientserverapi.lib.promise.ICommunicationPromise is in unnamed module of loader net.md_5.bungee.api.plugin.PluginClassloader @5460cf3a, parent loader 'app') at eu.thesimplecloud.module.permission.PermissionPool.<init>(PermissionPool.kt:51) at eu.thesimplecloud.module.permission.service.bungee.BungeePluginMain.onEnable(BungeePluginMain.kt:32) at net.md_5.bungee.api.plugin.PluginManager.enablePlugins(PluginManager.java:266) at net.md_5.bungee.BungeeCord.start(BungeeCord.java:298) at net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:67) at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15) 07:42:24 [INFO]
询问是否有办法绕过冲突,或是否存在不包含Kotlin的JDA版本。
解决方案
1. 使用无Kotlin依赖的JDA版本
JDA支持排除Kotlin依赖,你可以通过构建工具配置移除相关模块,避免版本冲突:
- Maven配置:
<dependency> <groupId>net.dv8tion</groupId> <artifactId>JDA</artifactId> <version>你的JDA版本号</version> <exclusions> <exclusion> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> </exclusion> <exclusion> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib-jdk8</artifactId> </exclusion> </exclusions> </dependency>
- Gradle配置:
implementation('net.dv8tion:JDA:你的版本号') { exclude group: 'org.jetbrains.kotlin' }
2. 隔离插件类加载器
通过类加载隔离或依赖重命名避免类冲突:
- 在BungeeCord插件的
plugin.yml中添加classloader: isolated,强制插件使用独立类加载器; - 使用Shadow插件(Maven/Gradle)打包时重命名Kotlin相关包路径,示例Maven配置:
<plugin> <groupId>com.github.johnrengelman</groupId> <artifactId>shadow-maven-plugin</artifactId> <version>7.1.2</version> <executions> <execution> <phase>package</phase> <goals> <goal>shadow</goal> </goals> <configuration> <relocations> <relocation> <pattern>kotlin</pattern> <shadedPattern>com.yourplugin.kotlin</shadedPattern> </relocation> <relocation> <pattern>org.jetbrains.kotlin</pattern> <shadedPattern>com.yourplugin.jetbrains.kotlin</shadedPattern> </relocation> </relocations> </configuration> </execution> </executions> </plugin>
3. 统一Kotlin版本
对齐JDA与SimpleCloud-Permissions的Kotlin版本,在构建工具中强制指定Kotlin版本,覆盖JDA自带版本:
- Maven配置:
<properties> <kotlin.version>与SimpleCloud一致的版本号</kotlin.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <version>${kotlin.version}</version> </dependency> </dependencies> </dependencyManagement>
内容的提问来源于stack exchange,提问作者Fedox
相关产品推荐
相关产品推荐

