Skip to content

Commit 4022bd0

Browse files
dmlloydgnodet
andauthored
[MCOMPILER-494] - Add a useModulePath switch to the testCompile mojo (#119)
Co-authored-by: Guillaume Nodet <[email protected]>
1 parent f4a8a54 commit 4022bd0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java

+18
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ public class TestCompilerMojo extends AbstractCompilerMojo {
161161
@Parameter(defaultValue = "${project.build.directory}/generated-test-sources/test-annotations")
162162
private File generatedTestSourcesDirectory;
163163

164+
/**
165+
* <p>
166+
* When {@code true}, uses the module path when compiling with a release or target of 9+ and
167+
* <em>module-info.java</em> or <em>module-info.class</em> is present.
168+
* When {@code false}, always uses the class path.
169+
* </p>
170+
*
171+
* @since 3.11
172+
*/
173+
@Parameter(defaultValue = "true")
174+
private boolean useModulePath;
175+
164176
@Parameter(defaultValue = "${project.testClasspathElements}", readonly = true)
165177
private List<String> testPath;
166178

@@ -288,6 +300,12 @@ protected void preparePaths(Set<File> sourceFiles) {
288300
testModuleDescriptor = result.getMainModuleDescriptor();
289301
}
290302

303+
if (!useModulePath) {
304+
pathElements = Collections.emptyMap();
305+
modulepathElements = Collections.emptyList();
306+
classpathElements = testPath;
307+
return;
308+
}
291309
if (StringUtils.isNotEmpty(getRelease())) {
292310
if (Integer.parseInt(getRelease()) < 9) {
293311
pathElements = Collections.emptyMap();

0 commit comments

Comments
 (0)