Java 在JMPS模块化应用程序中运行Spring引导测试代码时出错

Java 在JMPS模块化应用程序中运行Spring引导测试代码时出错,java,junit,java-module,java-platform-module-system,Java,Junit,Java Module,Java Platform Module System,我试图使用Java9中引入的JMPS创建一个模块化Spring引导示例 目前,我为测试工作创建了一个独立的Maven模块 module greeting.webapp.test{ 需要greeting.webapp; 需要弹簧试验; 需要spring.boot; 需要spring.web; 需要spring.boot.starter.webflux; 需要spring.boot.starter.test; 需要spring.boot.test; 需要spring.boot.test.autoco

我试图使用Java9中引入的JMPS创建一个模块化Spring引导示例

目前,我为测试工作创建了一个独立的Maven模块

module greeting.webapp.test{
需要greeting.webapp;
需要弹簧试验;
需要spring.boot;
需要spring.web;
需要spring.boot.starter.webflux;
需要spring.boot.starter.test;
需要spring.boot.test;
需要spring.boot.test.autoconfigure;
需要org.junit.jupiter;
需要org.junit.jupiter.api;
需要org.junit.jupiter.params;
需要org.junit.jupiter.engine;
需要org.junit.platform.commons;
需要org.assertj.core;
需要mockito.junit.jupiter;
}
当运行时,我得到了以下错误

线程“main”java.lang.IllegalAccessError中的异常:类org.junit.platform.launcher.TestIdentifier(在未命名模块@0x6325a3ee中)无法访问类org.junit.platform.commons.util.premissions(在模块org.junit.platform.commons中)因为模块org.junit.platform.commons不会将org.junit.platform.commons.util导出到未命名模块@0x6325a3ee
位于org.junit.platform.launcher.TestIdentifier.from(TestIdentifier.java:56)
位于com.intellij.junit5.JUnit5IdeaTestRunner。(JUnit5IdeaTestRunner.java:86)
位于java.base/java.lang.Class.forName0(本机方法)
位于java.base/java.lang.Class.forName(Class.java:377)
在com.intellij.rt.junit.JUnitStarter.getAgentClass(JUnitStarter.java:230)上
位于com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:210)
位于com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

在测试模块中,我必须将测试范围的dep迁移到编译时,以使其在jmps中工作,如何解决这个问题?

没有简单的方法,或者根本没有好的方法,imho

您遇到的问题是尚未配置。你可以试一下——我试过了,但不知何故很不走运,但我没有投入太多时间让它发挥作用(我也不认为这会起作用,但这是一个不同的问题)。相反,我通过以下方式手动配置了surefire插件:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <argLine>
                    --add-exports org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED
                    --add-exports org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED
                </argLine>
            </configuration>
        </plugin>

org.apache.maven.plugins
. 我也不认为IDE(
Intellij
在我的例子中)有适当的支持来运行单个(基于maven的项目)测试,这与gradle不同。但是,公平地说,到目前为止,我只是试着反对你的回购协议


您还可以阅读gradle在需要声明模块时采用的一种相当简洁的方法,以及它们的专用插件。

imho,没有简单的方法,或者根本没有好方法

您遇到的问题是尚未配置。你可以试一下——我试过了,但不知何故很不走运,但我没有投入太多时间让它发挥作用(我也不认为这会起作用,但这是一个不同的问题)。相反,我通过以下方式手动配置了surefire插件:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <argLine>
                    --add-exports org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED
                    --add-exports org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED
                </argLine>
            </configuration>
        </plugin>

org.apache.maven.plugins
. 我也不认为IDE(
Intellij
在我的例子中)有适当的支持来运行单个(基于maven的项目)测试,这与gradle不同。但是,公平地说,到目前为止,我只是试着反对你的回购协议


您还可以阅读gradle在需要声明模块时采用的一种相当简洁的方法,有他们专用的插件。

如果你能提供一些关于答案的反馈,那就太好了……如果你能提供一些关于答案的反馈,那就太好了……对于那些还没有准备好用于java模块的JAR来说,这可能是一种回退方式,JUnit本身是jmps模块化的,我仍然会遇到其他问题,当我以后关注它时,我会更新你。对于那些还没有准备好用于java模块的JAR,这可能是一种后备方法,JUnit本身是jmps模块化的,我仍然会遇到其他问题,当我稍后关注它时,我会更新你。