I have a multi-module maven project with three modules core
, utils
and test-utils
Core has the following dependencies definition
<dependency>
<groupId>my.project</groupId>
<artifactId>utils</artifactId>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>test-utils</artifactId>
<scope>test</scope>
</dependency>
I have added Java 9 module-info.java
definitions for all three modules and core
's looks like this:
module my.project.core {
requires my.project.utils;
}
However I cannot figure out how to get core
's test classes to be able to see the test-utils
classes during test execution. When maven-surefire-plugin
attempts the test run I get class not found.
If I add a requires my.project.testutils;
to core
's module-info.java
:
module my.project.core {
requires my.project.utils;
requires my.project.testutils; //test dependency
}
Then at compile time I get an error that the my.project.testutils
module can't be found (presumably because it's only brought in as a test dependency).
How does one work with test dependencies in a Java 9 modular world? For obvious reason's I don't want my main code to pull in test dependencies. Am I missing something?
module-info.java
with the tworequires
is definitely the wrong direction. Generally, in Java 9, tests are facilitated by 'patching' a module (Maven and Gradle tend to abstract this away). On another note, it is unclear if you have seen this doc re: toolchains? - maven.apache.org/surefire/maven-surefire-plugin/java9.html – Takamatsutest
scope (so I won't write it as an answer), but in case this helps, here is a small Java9 example using Maven - github.com/codetojoy/WarO_Java_9_Maven – Takamatsu