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

使用Maven执行自动化测试时遇Serenity插件兼容性错误求助

问题:Serenity Maven插件在高版本JDK下执行失败

运行自动化测试用例时,通过project>run as> maven install执行Maven,触发如下错误:

Failed to execute goal net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16:aggregate (serenity-reports) on project flightmode: Execution serenity-reports of goal net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16:aggregate failed: An API incompatibility was encountered while executing net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16:aggregate: java.lang.ExceptionInInitializerError: null

[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.16
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/XXXXX/.m2/repository/net/serenity-bdd/maven/plugins/serenity-maven-plugin/1.9.16/serenity-maven-plugin-1.9.16.jar
[ERROR] urls[1] = file:/C:/XXXX/.m2/repository/net/serenity-bdd/serenity-core/1.9.16/serenity-core-1.9.16.jar
[ERROR] urls[2] = file:/C:/XXXX/.m2/repository/com/google/guava/guava/23.6-jre/guava-23.6-jre.jar
[ERROR] urls[3] = file:/C:/XXXXX/.m2/repository/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar
........

[ERROR] : Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @7a972f12
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

系统环境

  • JDK版本:17.0.12
  • Maven版本:3.8.3

已尝试的操作

  • 切换至Java 21运行,问题未解决
  • 在eclipse.ini文件中添加以下配置,无效:
-Djava.security.manager=allow
--illegal-access=warn
--add-opens=java.base/java.lang=ALL-UNNAME

解决方案

1. 升级Serenity Maven插件及核心依赖版本

Serenity 1.9.16是2019年的旧版本,完全不支持JDK17+的模块系统,这是核心问题。建议升级到最新稳定版(如4.x系列):

修改项目pom.xml中的插件配置:

<plugin>
    <groupId>net.serenity-bdd.maven.plugins</groupId>
    <artifactId>serenity-maven-plugin</artifactId>
    <version>4.0.40</version> <!-- 替换为最新稳定版 -->
    <executions>
        <execution>
            <id>serenity-reports</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

同时升级Serenity核心依赖:

<dependency>
    <groupId>net.serenity-bdd</groupId>
    <artifactId>serenity-core</artifactId>
    <version>4.0.40</version> <!-- 与插件版本保持一致 -->
</dependency>

2. 修正JVM参数配置

之前的eclipse.ini参数存在拼写错误:ALL-UNNAME应为ALL-UNNAMED。此外,需要确保这些参数传递给Maven的JVM进程,而非仅Eclipse本身:

  • 在Eclipse的Maven运行配置中,添加VM参数:
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
  • 或者修改Maven全局配置(Windows为maven_home/bin/mvn.cmd,Linux/mac为maven_home/bin/mvn),添加JVM参数:
set MAVEN_OPTS=--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED

3. 升级Maven版本(可选)

Maven 3.8.3对JDK17的支持有限,升级到Maven 3.9.x版本可提升与高版本JDK的兼容性。

内容的提问来源于stack exchange,提问作者Manoj Soundarrajan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 02:47:24