-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add module-aware resource handling for modular sources #11505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add module-aware resource handling for modular sources #11505
Conversation
|
Hi @desruisseaux, I'd be happy to get some feedback from you (cf. my mail to the dev mailing list as of today), before making this an official PR. Thanks |
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Outdated
Show resolved
Hide resolved
| * @param sources list of source elements from the build | ||
| * @return set of non-blank module names | ||
| */ | ||
| private Set<String> extractModules(List<org.apache.maven.api.model.Source> sources) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method could be static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 0c2451e. Made extractModules method static.
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Outdated
Show resolved
Hide resolved
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Outdated
Show resolved
Hide resolved
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Outdated
Show resolved
Hide resolved
3e2d01f to
bef10a1
Compare
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Outdated
Show resolved
Hide resolved
impl/maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java
Outdated
Show resolved
Hide resolved
Maven 4.x introduces a unified <sources> element that supports modular project layouts (src/<module>/<scope>/<lang>). However, resource handling did not follow the modular layout - resources were always loaded from the legacy <resources> element which defaults to src/main/resources. This change implements automatic module-aware resource injection: - Detect modular projects (projects with at least one module in sources) - For modular projects without resource configuration in <sources>, automatically inject resource roots following the modular layout: src/<module>/main/resources and src/<module>/test/resources - Resources configured via <sources> take priority over legacy <resources> - Issue warnings (as ModelProblem) when explicit legacy resources are ignored Example: A project with modular sources for org.foo.moduleA will now automatically pick up resources from: - src/org.foo.moduleA/main/resources - src/org.foo.moduleA/test/resources This eliminates the need for explicit maven-resources-plugin executions when using modular project layouts.
- Rename hasOnlySuperPomDefaults to hasExplicitLegacyResources with inverted logic to avoid double negations in predicates - Remove redundant isEmpty() checks now handled by the method - Make extractModules method static Note: Extracting a shared method for main/test resource handling was not possible due to checkstyle ParameterNumber limit (max 7). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Refactor duplicate resource handling code into a shared method: - Add ResourceHandlingContext record to group shared parameters - Add handleResourceConfiguration method (4 parameters vs 9) - Remove unused outputDirectory param from createModularResourceRoot - Replace ~120 lines of duplicate code with 7 lines This addresses PR review comment apache#1 about code duplication between main and test resource handling blocks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Rename 'ctx' to 'context' in DefaultProjectBuilder - Use short form 'ModelProblem' instead of FQCN in test Addresses review comments from elharo on PR apache#11505. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
bef10a1 to
f747693
Compare
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Outdated
Show resolved
Hide resolved
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Outdated
Show resolved
Hide resolved
Use {@code <element>} instead of <element> escapes in javadoc
for better readability in source code (per Martin's suggestion).
Addresses review comment from desruisseaux on PR apache#11505.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Avoid abbreviations in new code per project conventions. Addresses review comment from elharo on PR apache#11505. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Avoid abbreviations in new code per project conventions. Addresses review comment from elharo on PR apache#11505. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
bdb4c3f to
ee7f1d3
Compare
Summary
<sources>layoutsrc/<module>/main/resourcesandsrc/<module>/test/resources<resources>configuration is ignored in favor of modular defaultsProblem
Projects using Maven 4.x modular sources (
<source><module>org.foo.bar</module></source>) had to manually configuremaven-resources-pluginfor each module. Resources from the modular layout paths were not automatically discovered.Solution
When a project defines at least one module in
<sources>:<resources>from Super POM defaults are silently replaced<resources>configuration triggers aModelProblemwarningTest plan
testModularSourcesInjectResourceRoots- verifies resource injection for multi-module projectstestModularSourcesWithExplicitResourcesIssuesWarning- verifies warnings are issued when legacy resources are ignored