Add module-aware resource handling for modular sources
Summary
- Automatically inject module-aware resource roots for projects using modular
<sources>layout - Resources are picked up from
src/<module>/main/resourcesandsrc/<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>:
- Modular resource roots are automatically injected for each module
- Legacy
<resources>from Super POM defaults are silently replaced - Explicit legacy
<resources>configuration triggers aModelProblemwarning
Test plan
- [x]
testModularSourcesInjectResourceRoots- verifies resource injection for multi-module projects - [x]
testModularSourcesWithExplicitResourcesIssuesWarning- verifies warnings are issued when legacy resources are ignored
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
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?
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.
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?
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.