-
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
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
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
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
bef10a1 to
f747693
Compare
- 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]>
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
|
Could someone please add the |
impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
Show resolved
Hide resolved
gnodet
left a comment
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.
I think we should reject any project that mixes <resource> and <source> elements, I don't see that as a valid use case.
I think this should even be done in |
Thanks for the feedback, @gnodet. Having said that, this PR is just about the first part of the problem (make Maven Core handle resources at all). Perhaps we can focus here on that feature? |
|
I would also suggest to reject any project that mixes |
Once the PR is merged (and a new version of Maven is published) we should be able to perform a simplified build wrt Maven resources.
3b2af3a to
d2ce972
Compare
- 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]>
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
- Change debug logging to trace level for reduced verbosity - Add periods to end of all log/warning messages - Use else blocks to avoid redundant logging after warnings - Make hasExplicitLegacyResources and createModularResourceRoot static - Remove low-level debug log from hasExplicitLegacyResources - Simplify loop logging by using context.modules() directly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
impl/maven-core/src/main/java/org/apache/maven/project/ResourceHandlingContext.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]>
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]>
- Change debug logging to trace level for reduced verbosity - Add periods to end of all log/warning messages - Use else blocks to avoid redundant logging after warnings - Make hasExplicitLegacyResources and createModularResourceRoot static - Remove low-level debug log from hasExplicitLegacyResources - Simplify loop logging by using context.modules() directly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Move resource handling logic to dedicated package-private class: - Create ResourceHandlingContext with project-level state - Method handleResourceConfiguration(scope, hasResourcesInSources) derives resources from scope, takes flag as parameter - Reduces DefaultProjectBuilder by 179 lines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Per PR apache#11505 review feedback from desruisseaux: the logs in handleResourceConfiguration are the result of more elaborated analysis and should remain at debug level, not trace. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
dcc621c to
dc90ada
Compare
|
Thanks! I will wait a little bit in case there is some comment, and if none I propose to merge this weekend. |
|
@desruisseaux Please assign appropriate label to PR according to the type of change. |
|
Thanks a lot for merging, @desruisseaux. |
|
Yes I thought about that. But as you mentioned on the slack channel, the work done in this pull request could be generalized. I thought that what this PR does for resources, the same thing could be done for tests. I'm thinking to refactor the |
Yes, I have a Phase 2 implementation in my mind which would be more general. Nevertheless, the feature would already be helpful (and I'd be eager to get it in the next Release Candidate for Maven 4.0).
Sounds good, perhaps we can join forces in the next weeks to get a combined implementation? |
|
Maybe you can go ahead with phase 2 when you have time. Looking on the wiki page, I suggest the following changes:
|
|
I have raised a new issue (#11612) for further discussion. |
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