From 4022bd0f37626124dad394b2e4583fd6768fa74a Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Mon, 13 Feb 2023 06:17:46 -0600 Subject: [PATCH] [MCOMPILER-494] - Add a `useModulePath` switch to the `testCompile` mojo (#119) Co-authored-by: Guillaume Nodet --- .../plugin/compiler/TestCompilerMojo.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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();