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

Maven 3.9.6+Java22搭建项目遇Serenity类文件版本解析错误

解决Maven Serenity报错:Failed to resolve the class file version of the current VM: Unknown Java version: 0

问题原因

这个错误是因为你使用的Serenity版本未适配Java 22。Java 22的class文件版本号是66,旧版Serenity的版本映射表中没有这个版本,导致无法识别当前JVM版本,抛出该错误。

解决步骤

  • 升级Serenity依赖到支持Java 22的版本:确保Serenity Core和Maven插件至少升级到3.9.0及以上版本(该版本开始支持Java 21+,兼容Java 22)。在POM文件中更新相关依赖:
<!-- Serenity Core依赖 -->
<dependency>
    <groupId>net.serenity-bdd</groupId>
    <artifactId>serenity-core</artifactId>
    <version>3.9.0</version>
</dependency>

<!-- Serenity Maven插件 -->
<plugin>
    <groupId>net.serenity-bdd.maven.plugins</groupId>
    <artifactId>serenity-maven-plugin</artifactId>
    <version>3.9.0</version>
    <executions>
        <execution>
            <id>serenity-reports</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>
  • 验证Maven使用的Java版本:在终端执行mvn -v,确认输出的Java版本为22。如果不是,检查并设置JAVA_HOME环境变量指向Java 22的安装目录。
  • 清理Maven缓存并重新构建:执行mvn clean install -U,强制清理缓存并更新依赖,避免旧缓存干扰。
  • 确认IntelliJ的Maven Runner配置:进入Settings > Build, Execution, Deployment > Build Tools > Maven > Runner,确保JRE选项选择的是Java 22,而非其他版本。

内容的提问来源于stack exchange,提问作者vacant desk

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 11:48:12