将模块导出添加到 mvn 测试执行运行时
Adding module export to mvn test execution runtime
在测试期间出现此错误:
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 进行了交叉检查,用 add-opens 配置 surefire 应该是绝对足够的 Oracle's Migration Guide
你的格式也完全正确:--add-opens <module>/<package>=ALL-UNNAMED
。结合 --illegal-access=permit
它应该可以正常工作。
我只看到一个选项:从您的 opens-argument 中删除 =ALL-UNNAMED,这将使 VM/Surefire 崩溃并证明您的设置有效。
除此之外,您的测试 类 应该由您最喜欢的运行程序通过反射调用(测试方法包私有/不带 public-修饰符)。这需要为您的测试使用相同的 opens-declaration 类/ 导致相同的问题 – 除非 Maven 项目本身不是模块。
也许可以在你的问题中澄清这一点。
许多教程和指南发布了以下解决方法
<forkCount>0</forkCount>
请勿使用!
surefire 子进程是必须的,尤其是在 JPMS 中。
请不要应用 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。
在测试期间出现此错误:
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 进行了交叉检查,用 add-opens 配置 surefire 应该是绝对足够的 Oracle's Migration Guide
你的格式也完全正确:--add-opens <module>/<package>=ALL-UNNAMED
。结合 --illegal-access=permit
它应该可以正常工作。
我只看到一个选项:从您的 opens-argument 中删除 =ALL-UNNAMED,这将使 VM/Surefire 崩溃并证明您的设置有效。
除此之外,您的测试 类 应该由您最喜欢的运行程序通过反射调用(测试方法包私有/不带 public-修饰符)。这需要为您的测试使用相同的 opens-declaration 类/ 导致相同的问题 – 除非 Maven 项目本身不是模块。
也许可以在你的问题中澄清这一点。
许多教程和指南发布了以下解决方法
<forkCount>0</forkCount>
请勿使用!
surefire 子进程是必须的,尤其是在 JPMS 中。
请不要应用 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。