问题描述
在测试过程中出现此错误:
class javax.crypto.JceSecurity (in unnamed module @0x45da40ad) cannot access class jdk.internal.util.StaticProperty (in module java.base) because module java.base does not export jdk.internal.util to unnamed module @0x45da40ad
我尝试在根目录下创建pom.xml旁边的jvm.config
--add-modules ALL-SYstem
--add-opens java.base/jdk.internal.util=ALL-UNNAMED
--illegal-access=permit
这不会改变任何东西。 所以我尝试像这样配置Maven编译器插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>--add-modules</arg>
<arg>ALL-SYstem</arg>
<arg>--add-opens</arg>
<arg>java.base/jdk.internal.util=ALL-UNNAMED</arg>
</compilerArgs>
<argLine>
--add-modules ALL-SYstem
--add-opens java.base/jdk.internal.util=ALL-UNNAMED
--illegal-access=permit
</argLine>
<source>${java.compiler.source}</source>
<target>${java.compiler.target}</target>
</configuration>
</plugin>
为了记录,我什至尝试这样做:
<argLine>
--add-modules ALL-SYstem
--add-opens java.base/jdk.internal.util=ALL-UNNAMED
--illegal-access=permit
</argLine>
什么都没有。然后我尝试像这样的surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<forkCount>0</forkCount>
<argLine>
--add-modules ALL-SYstem
--add-opens java.base/jdk.internal.util=ALL-UNNAMED
--illegal-access=permit
</argLine>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
两天的时间,但失败了。请帮忙。使用OpenJdk11
解决方法
我与surefire 3.0.0-M3和-M5进行了交叉检查,并且绝对可以通过添加Oracle's Migration Guide来配置surefire
您的格式也绝对正确:--add-opens <module>/<package>=ALL-UNNAMED
。与--illegal-access=permit
结合使用,应该可以正常工作。
我仅看到一个选项:从打开参数中删除= ALL-UNNAMED,这将使VM / Surefire崩溃并证明您的设置处于活动状态。
此外,您的测试类还应该由您最喜欢的跑步者通过反射来调用(测试方法包private /不带public-modifier)。这需要为您的测试类使用相同的打开声明/引起相同的问题-除非Maven项目本身不是一个模块。
也许可以在您的问题中澄清一下。
,许多教程和指南发布了以下解决方法
<forkCount>0</forkCount>
请不要使用它!
特别是在JPMS中,surefire子流程是必须的。
请不要对 forkCount = 0 应用变通办法,而应报告Apache JIRA中的错误并与开源开发人员进行沟通。
,感谢其他答案,这有助于我更深入地研究。我设法通过以下pom更改来解决它
<properties>
<!-- Must be in pom's properties section. <sonar.jacoco.reportPaths>target/coverage.exec</sonar.jacoco.reportPaths> -->
<jacoco.version>0.7.7.201606060606</jacoco.version>
<!-- Used by surefire plugin run tests with openjdk11 -->
<argLine>--add-modules java.base --add-opens java.base/jdk.internal.util=ALL-UNNAMED --illegal-access=permit</argLine>
</properties>
.........
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.compiler.source}</source>
<target>${java.compiler.target}</target>
</configuration>
</plugin>
........
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
基本上,我必须将argline放入属性中。编译器似乎不需要它,因为它不是从那里拿起的。但是surefire确实是,它是从maven的属性读取argline的。