Skip to content

Conversation

@ascheman
Copy link

Summary

  • Automatically inject module-aware resource roots for projects using modular <sources> layout
  • Resources are picked up from src/<module>/main/resources and src/<module>/test/resources
  • Issue warnings when explicit legacy <resources> configuration is ignored in favor of modular defaults

Problem

Projects using Maven 4.x modular sources (<source><module>org.foo.bar</module></source>) had to manually configure maven-resources-plugin for each module. Resources from the modular layout paths were not automatically discovered.

Solution

When a project defines at least one module in <sources>:

  1. Modular resource roots are automatically injected for each module
  2. Legacy <resources> from Super POM defaults are silently replaced
  3. Explicit legacy <resources> configuration triggers a ModelProblem warning

Test plan

  • testModularSourcesInjectResourceRoots - verifies resource injection for multi-module projects
  • testModularSourcesWithExplicitResourcesIssuesWarning - verifies warnings are issued when legacy resources are ignored

@ascheman
Copy link
Author

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.
It affects the handling of resources as we recently as issue on my Java Modules examples.

Thanks
Gerd

* @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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method could be static.

Copy link
Author

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.

@ascheman ascheman force-pushed the feature/maven-4-resource-handling branch from 3e2d01f to bef10a1 Compare December 3, 2025 17:51
ascheman and others added 4 commits December 13, 2025 09:54
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]>
@ascheman ascheman force-pushed the feature/maven-4-resource-handling branch from bef10a1 to f747693 Compare December 13, 2025 09:17
elharo
elharo previously requested changes Dec 13, 2025
Use {@code <element>} instead of &lt;element&gt; 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]>
ascheman added a commit to support-and-care/maven that referenced this pull request Dec 14, 2025
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]>
@ascheman ascheman force-pushed the feature/maven-4-resource-handling branch from bdb4c3f to ee7f1d3 Compare December 14, 2025 09:57
@elharo elharo dismissed their stale review December 14, 2025 12:05

addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants