Copilot commented on code in PR #1093:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/1093#discussion_r3673585903


##########
src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java:
##########
@@ -342,23 +350,22 @@ protected void preparePaths(Set<File> sourceFiles) {
                 }
 
                 if 
(testModuleDescriptor.name().equals(mainModuleDescriptor.name())) {
-                    if (compilerArgs == null) {
-                        compilerArgs = new ArrayList<>();
-                    }
-                    compilerArgs.add("--patch-module");
-
-                    StringBuilder patchModuleValue = new StringBuilder();
-                    patchModuleValue.append(testModuleDescriptor.name());
-                    patchModuleValue.append('=');
-
+                    List<String> mainSourceRoots = new ArrayList<>();
                     for (String root : getProject().getCompileSourceRoots()) {
                         if (Files.exists(Paths.get(root))) {
-                            patchModuleValue.append(root).append(PS);
+                            mainSourceRoots.add(root);
                         }
                     }
 
-                    compilerArgs.add(patchModuleValue.toString());
+                    // Tests in the main module need the layered MR-JAR output 
and the main sources as one patch.
+                    List<File> outputPatches =
+                            mainOutputDirectories.size() > 1 ? 
mainOutputDirectories : Collections.emptyList();
+                    addPatchModule(testModuleDescriptor.name(), outputPatches, 
mainSourceRoots);
                 } else {
+                    // The selected descriptor directory represents the main 
module; patch in the remaining layers.
+                    if (mainOutputDirectories.size() > 1) {
+                        addPatchModule(mainModuleDescriptor.name(), 
mainOutputDirectories, Collections.emptyList());
+                    }

Review Comment:
   The comment says “patch in the remaining layers”, but 
`mainOutputDirectories` includes the directory that contains the selected 
`module-info.class`. Patching the main module with the same directory that 
already represents the main module can also re-introduce `module-info.class` on 
the patch path, which risks duplicate module descriptor discovery or unexpected 
javac behavior. Consider excluding 
`mainModuleDescriptorClassFile.getParentFile()` from the patch list (e.g., 
patch only the other layers) so the patch path truly represents “remaining” 
layers.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to