You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2023/02/13 12:17:52 UTC

[maven-compiler-plugin] branch master updated: [MCOMPILER-494] - Add a `useModulePath` switch to the `testCompile` mojo (#119)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 4022bd0  [MCOMPILER-494] - Add a `useModulePath` switch to the `testCompile` mojo (#119)
4022bd0 is described below

commit 4022bd0f37626124dad394b2e4583fd6768fa74a
Author: David M. Lloyd <da...@redhat.com>
AuthorDate: Mon Feb 13 06:17:46 2023 -0600

    [MCOMPILER-494] - Add a `useModulePath` switch to the `testCompile` mojo (#119)
    
    Co-authored-by: Guillaume Nodet <gn...@gmail.com>
---
 .../apache/maven/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 4bbdc7e..d091825 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;
 
+    /**
+     * <p>
+     * When {@code true}, uses the module path when compiling with a release or target of 9+ and
+     * <em>module-info.java</em> or <em>module-info.class</em> is present.
+     * When {@code false}, always uses the class path.
+     * </p>
+     *
+     * @since 3.11
+     */
+    @Parameter(defaultValue = "true")
+    private boolean useModulePath;
+
     @Parameter(defaultValue = "${project.testClasspathElements}", readonly = true)
     private List<String> testPath;
 
@@ -288,6 +300,12 @@ public class TestCompilerMojo extends AbstractCompilerMojo {
             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();