微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将模块导出添加到MVN测试执行运行时

如何解决将模块导出添加到MVN测试执行运行时

在测试过程中出现此错误

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的。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。