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


##########
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:
   When we compile a multi-module project by a single call to `javac`, we let 
the Java compiler manages the dependencies between modules. This is one of the 
reasons for supporting this feature, because Maven dependencies are restricted 
to acyclic graphs while Java module dependencies accept a limited form of 
cyclic dependencies (e.g. in qualified exports).
   
   If we run the compiler twice for producing the no-module JAR, we would have 
to manage its dependency relatively to the modular JARs. Do we compile the 
legacy source base before the modules, then add the legacy output on the 
class-path of all modules? Or do we compile the modules first, then add them on 
the module-path for compiling the legacy source? In the latter case, do we add 
all modules or a subset of them? There is no `module-info` for telling us which 
subset of the `pom.xml` dependencies is effective for the legacy JAR.
   
   It was a choice to stick to "one sub-project = one compilation unit" for the 
main code (ignoring tests and multi-release for this discussion). By requiring 
legacy source base to be compiled in its own Maven sub-project, we let the 
developers decide if the legacy source base depends on the modules or the 
converse, which modules, whether a module is optional, and whether to place 
them on the class-path or module-path. By contrast, if the Maven Compiler 
Plugin did two compilations for supporting modular sources and legacy sources 
in the same sub-project, we would be forced to take many arbitrary decisions.



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