maven icon indicating copy to clipboard operation
maven copied to clipboard

Add module-aware resource handling for modular sources

Open ascheman opened this issue 1 month ago • 1 comments

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

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

ascheman avatar Nov 30 '25 13:11 ascheman

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

ascheman avatar Nov 30 '25 13:11 ascheman

Could someone please add the backport-to-4.0.x label as it would be great to have this change one of the next RCs?

ascheman avatar Dec 16 '25 07:12 ascheman

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 org.apache.maven.impl.model.DefaultModelValidator.

gnodet avatar Dec 16 '25 08:12 gnodet

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 org.apache.maven.impl.model.DefaultModelValidator.

Thanks for the feedback, @gnodet. Personally, I am with you, cf. my lengthy discussion about the topic in Confluence. I was proposing two approaches (warnings/lenient vs. errors/strict). How could we get a stronger vote about it (with more opinions than just yours and mine)?

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?

ascheman avatar Dec 16 '25 09:12 ascheman

I would also suggest to reject any project that mixes <resource> and <source> elements. Since <source> is new in Maven 4, we are not yet breaking any existing project. If this policy is too strict, we can relax later. The opposite is much more difficult to do.

desruisseaux avatar Dec 16 '25 10:12 desruisseaux