From 7de55c407a6c9403bad65c217b612167874920a8 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Thu, 28 Apr 2022 08:47:31 -0500 Subject: [PATCH] [MCOMPILER-494] - Add a `useModulePath` switch to the `testCompile` mojo --- .../plugin/compiler/TestCompilerMojo.java | 19 +++++++++++++++++++ 1 file changed, 19 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 9d9469f6..43f72a5a 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java @@ -153,6 +153,18 @@ public class TestCompilerMojo @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; @@ -304,6 +316,13 @@ protected void preparePaths( Set sourceFiles ) testModuleDescriptor = result.getMainModuleDescriptor(); } + if ( ! useModulePath ) + { + pathElements = Collections.emptyMap(); + modulepathElements = Collections.emptyList(); + classpathElements = testPath; + return; + } if ( release != null ) { if ( Integer.valueOf( release ) < 9 )