desruisseaux commented on code in PR #11702:
URL: https://github.com/apache/maven/pull/11702#discussion_r2812140029


##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -692,49 +692,102 @@ private void initProject(MavenProject project, 
ModelBuilderResult result) {
                 }
 
                 /*
-                 * `sourceDirectory`, `testSourceDirectory` and 
`scriptSourceDirectory`
-                 * are ignored if the POM file contains at least one enabled 
<source> element
-                 * for the corresponding scope and language. This rule exists 
because
-                 * Maven provides default values for those elements which may 
conflict
-                 * with user's configuration.
+                 * Source directory handling depends on project type and 
<sources> configuration:
                  *
-                 * Additionally, for modular projects, legacy directories are 
unconditionally
-                 * ignored because it is not clear how to dispatch their 
content between
-                 * different modules. A warning is emitted if these properties 
are explicitly set.
+                 * 1. CLASSIC projects (no <sources>):
+                 *    - All legacy directories are used
+                 *
+                 * 2. MODULAR projects (have <module> in <sources>):
+                 *    - ALL legacy directories are rejected (can't dispatch 
between modules)
+                 *    - Physical presence of default directories 
(src/main/java) also triggers ERROR

Review Comment:
   The concept of unnamed modules usually applies to dependencies: a JAR placed 
on the class-path is an unnamed module. This concept does not really applies to 
the sources to compile, unless we interpret "unnamed module" as "sources 
without module-info".
   
   We cannot mix sources for Java modules and sources without module-info in 
the same compilation unit. Either the Maven sub-project is fully modular, or 
either it does not use module source hierarchy at all. From  [javac man 
page](https://docs.oracle.com/en/java/javase/25/docs/specs/man/javac.html#additional-source-files)
 about the `--source-path` and `--module-source-path` options:
   
   > You can only specify one of these options: if you are not compiling code 
for a module, or if you are only compiling code for a single module, use the 
source path; if you are compiling code for multiple modules, use the module 
source path.
   
   Therefore, a Maven project using `<module>` cannot accept unnamed module. If 
a developer wants an unnamed module, it must be a separated Maven sub-project.



-- 
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