diff --git a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java index 4bbdc7e0..d091825e 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java @@ -161,6 +161,18 @@ public class TestCompilerMojo extends AbstractCompilerMojo { @Parameter(defaultValue = "${project.build.directory}/generated-test-sources/test-annotations") private File generatedTestSourcesDirectory; + /** + *

+ * When {@code true}, uses the module path when compiling with a release or target of 9+ and + * module-info.java or module-info.class is present. + * When {@code false}, always uses the class path. + *

+ * + * @since 3.11 + */ + @Parameter(defaultValue = "true") + private boolean useModulePath; + @Parameter(defaultValue = "${project.testClasspathElements}", readonly = true) private List testPath; @@ -288,6 +300,12 @@ protected void preparePaths(Set sourceFiles) { testModuleDescriptor = result.getMainModuleDescriptor(); } + if (!useModulePath) { + pathElements = Collections.emptyMap(); + modulepathElements = Collections.emptyList(); + classpathElements = testPath; + return; + } if (StringUtils.isNotEmpty(getRelease())) { if (Integer.parseInt(getRelease()) < 9) { pathElements = Collections.emptyMap();