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


##########
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:
   `resources.isEmpty()` is already tested by `hasOnlySuperPomDefaults`, so it 
is not necessary to repeat the test here.



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