You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven添加Mythic-Dist依赖遇类版本不兼容问题求助

问题描述

为Maven项目添加Mythic-Dist依赖时遇到JDK版本不兼容问题:该依赖编译使用的class version为60(对应Java 16),但项目使用JDK 8(class version 52),报错如下:

(Can't process class [io/lumine/mythic/core/Joshinn.class] (Unsupported class version number [60.0] (maximum 52.0, Java 1.8)))

同时项目使用ProGuard,误以为ProGuard无法适配更高版本JDK,不知如何处理。项目的pom.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.civious.dungeonmmo</groupId>
    <artifactId>DungeonMMO</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <build>
        <defaultGoal>clean package</defaultGoal>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <jarName>DungeonMMO</jarName>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.0.13</version>
                <executions>
                    <execution>
                        <id>obfuscation-packaging</id>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                        <configuration>
                            <injar>DungeonMMO.jar</injar>
                            <obfuscate>true</obfuscate>
                            <attach>true</attach>
                            <appendClassifier>false</appendClassifier>
                            <addMavenDescriptor>true</addMavenDescriptor>
                            <libs>
                                <lib>${java.home}/lib/rt.jar</lib>
                            </libs>

                            <options>
                                <option>-dontshrink</option>
                                <option>-dontoptimize</option>
                                <option>-dontnote **</option>
                                <option>-dontwarn **</option>
                                <option>-target 1.8</option>
                                <!-- Keeping Main class -->
                                <option>-keep class
                                    com.civious.dungeonmmo.DungeonMMO
                                </option>
                                <option>-keepclassmembers class * extends java.lang.Enum {
                                    <![CDATA[<fields>]]>;
                                    public static **[] values();
                                    public static ** valueOf(java.lang.String);
                                    }
                                </option>
                                <option>-keepattributes !LocalVariableTable,!LocalVariableTypeTable</option>
                            </options>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>

        <repository>
            <id>bungeecord-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>

        <repository>
            <id>Multiverse-Core</id>
            <url>https://repo.onarandombox.com/content/repositories/multiverse/</url>
        </repository>

        <repository>
            <id>nexus</id>
            <name>Lumine Releases</name>
            <url>https://mvn.lumine.io/repository/maven-public/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.onarandombox.multiversecore</groupId>
            <artifactId>Multiverse-Core</artifactId>
            <version>4.3.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.bukkit</groupId>
                    <artifactId>bukkit</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.bukkit</groupId>
                    <artifactId>craftbukkit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.17-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.5.Final</version>
        </dependency>

        <dependency>
            <groupId>io.lumine</groupId>
            <artifactId>Mythic-Dist</artifactId>
            <version>5.0.3-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

</project>
解决方案

方案1:降级Mythic-Dist到兼容JDK 8的版本

查找Mythic-Dist的版本历史,选择编译目标为JDK 8的旧版本(如4.x系列),修改pom.xml中的依赖版本:

<dependency>
    <groupId>io.lumine</groupId>
    <artifactId>Mythic-Dist</artifactId>
    <!-- 替换为兼容JDK8的版本 -->
    <version>4.1.0</version>
    <scope>provided</scope>
</dependency>

此方案无需改动项目JDK配置,适配成本最低。

方案2:升级项目JDK版本并适配ProGuard

ProGuard完全支持高版本JDK,你的认知存在偏差。可将项目JDK升级到16或更高(匹配Mythic-Dist的class version 60),同步调整配置:

  1. 修改Maven编译属性:
<properties>
    <maven.compiler.source>16</maven.compiler.source>
    <maven.compiler.target>16</maven.compiler.target>
</properties>
  1. 更新ProGuard插件到最新稳定版(如3.2.2),旧版本对高JDK支持有限:
<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>3.2.2</version>
    <configuration>
        <options>
            <option>-target 16</option>
            <!-- 其余配置保持不变 -->
        </options>
    </configuration>
</plugin>
  1. 本地安装JDK 16,并在IDE中切换项目JDK版本。

方案3:配置ProGuard跳过Mythic-Dist类处理

由于Mythic-Dist的scope为provided(运行时由环境提供),可让ProGuard跳过对该依赖类的处理:
在ProGuard插件的<options>中添加规则:

<option>-dontwarn io.lumine.mythic.**</option>
<option>-keep class io.lumine.mythic.** { *; }</option>
<option>-dontprocess io.lumine.mythic.**</option>

注意:此方案仅适用于你的代码未使用JDK 8以上特性的情况,否则运行时仍会报错。

内容的提问来源于stack exchange,提问作者Alex _

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 06:11:15