美文网首页
mvn test报错module java.base does

mvn test报错module java.base does

作者: 洪兴掌管一代 | 来源:发表于2023-09-17 13:42 被阅读0次

    原因:这是jdk版本兼容问题。jdk8的反射相关功能在jdk9之后被限制。

    为了兼容旧版本,只需在启动时增加参数来开启默认不被允许的行为:

    --add-opens java.base/java.lang=ALL-UNNAMED

    因为我们的问题是在测试阶段发生,所以在pom.xml的maven-surefire-plugin插件中加入黑体的内容。关于插件的作用,见官网https://maven.apache.org/surefire/maven-surefire-plugin/

    <plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-surefire-plugin</artifactId>

    <configuration>

    <reuseForks>true</reuseForks>

    <forkCount>1</forkCount>

    <argLine>

    -Dio.netty.tryReflectionSetAccessible=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED

    --add-opens java.base/java.lang=ALL-UNNAMED

    --add-opens java.base/java.lang.reflect=ALL-UNNAMED

    </argLine>

    </configuration>

    </plugin>

    相关文章

      网友评论

          本文标题:mvn test报错module java.base does

          本文链接:https://www.haomeiwen.com/subject/iqkwvdtx.html