我正在GitHub上创建模块化构建(使用module-info.java),但是当我将module-info.java添加到我想要模块化的模块时,不能执行任何测试......
我怎样才能做到这一点?
我使用以下版本:
失败测试的典型错误如下:
java.lang.reflect.InaccessibleObjectException:无法访问com.github.jactor.rises.commons.dto.UserDtoTest():模块jactor.rises.commons不会"打开com.github.jactor.rises.commons.dto"到未命名的模块@ 65e98b1c
我有三个模块的多模块Maven项目core,utils以及test-utils
Core具有以下依赖项定义
<dependency>
<groupId>my.project</groupId>
<artifactId>utils</artifactId>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>test-utils</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我module-info.java为所有三个模块添加了Java 9 定义,它们core看起来像这样:
module my.project.core {
requires my.project.utils;
}
Run Code Online (Sandbox Code Playgroud)
但是我无法弄清楚如何让core测试类能够test-utils在测试执行期间看到类.当maven-surefire-plugin尝试测试运行时,我找不到课程.
如果我添加一个requires my.project.testutils;到core的module-info.java:
module my.project.core {
requires my.project.utils;
requires my.project.testutils; //test dependency
}
Run Code Online (Sandbox Code Playgroud)
然后在编译时我得到一个错误,my.project.testutils模块无法找到(大概是因为它只是作为测试依赖项引入).
如何在Java 9模块化世界中使用测试依赖项?出于显而易见的原因,我不希望我的主代码引入测试依赖项.我错过了什么吗?
java maven java-platform-module-system maven-surefire-plugin java-9