ascheman commented on code in PR #11505:
URL: https://github.com/apache/maven/pull/11505#discussion_r2586108429


##########
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java:
##########
@@ -700,11 +709,149 @@ private void initProject(MavenProject project, 
ModelBuilderResult result) {
                 if (!hasTest) {
                     
project.addTestCompileSourceRoot(build.getTestSourceDirectory());
                 }
-                for (Resource resource : 
project.getBuild().getDelegate().getResources()) {
-                    project.addSourceRoot(new DefaultSourceRoot(baseDir, 
ProjectScope.MAIN, resource));
+                // Extract modules from sources to detect modular projects
+                Set<String> modules = extractModules(sources);
+                boolean isModularProject = !modules.isEmpty();
+
+                logger.debug(
+                        "Module detection for project {}: found {} module(s) 
{} - modular project: {}",
+                        project.getId(),
+                        modules.size(),
+                        modules,
+                        isModularProject);
+
+                /*
+                 * Handle main resources - modular project has highest 
priority:
+                 * 1. Modular project: use resources from <sources> if 
present, otherwise inject defaults
+                 * 2. Classic project: use resources from <sources> if 
present, otherwise use legacy <resources>
+                 */
+                List<Resource> resources = 
project.getBuild().getDelegate().getResources();
+                if (isModularProject) {
+                    if (hasMainResources) {
+                        // Modular project with resources configured via 
<sources> - already added above
+                        if (!resources.isEmpty()

Review Comment:
   Done in 0c2451e7a30f8f427347b6c8b10bca3f551db02d. Removed the redundant 
isEmpty() checks and renamed the method to hasExplicitLegacyResources with 
inverted logic for clearer semantics (returns false when empty, true when 
explicit legacy resources exist).



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