Fix targetPath parameter ignored in resource bundles (fixes #11062) by mbaurin · Pull Request #11063 · apache/maven (original) (raw)
Following this checklist to help us incorporate your
contribution quickly and easily:
- Your pull request should address just one issue, without pulling in other changes.
- Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge.
- Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
This may not always be possible but is a best-practice. - Run
mvn verifyto make sure basic checks pass. A more thorough check will be performed on your pull request automatically. - You have run the Core IT successfully.
If your pull request is about ~20 lines of code you don't need to sign an Individual Contributor License Agreement if you are unsure please ask on the developers list.
To make clear that you license your contribution under the Apache License Version 2.0, January 2004 you have to acknowledge this by using the following check-box.
- I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
- In any other case, please file an Apache Individual Contributor License Agreement.
Summary
Fixes the regression where targetPath parameter in <resources> and <testResources> was being ignored in Maven 4.0.0-rc-4, causing resources to be copied to incorrect locations.
Root Cause
The issue was introduced in commit 0d7b61a4b4 with the new ConnectedResource implementation, which had three critical bugs that caused targetPath to be lost during resource processing.
Changes Made
- Fixed ConnectedResource constructor (
ConnectedResource.java:44)- Added missing
.targetPath()to Resource.newBuilder() chain - Extracts targetPath from SourceRoot using
sourceRoot.targetPath().map(path -> path.toString()).orElse(null)
- Added missing
- Fixed DefaultSourceRoot constructor (
DefaultSourceRoot.java:120-121)- Replaced hardcoded
targetPath = nullwith proper Resource extraction - Added
value = nonBlank(resource.getTargetPath()); targetPath = (value != null) ? baseDir.resolve(value) : null;
- Replaced hardcoded
- Fixed MavenProject.toResource method (
MavenProject.java:831)- Added targetPath inclusion when converting SourceRoot to Resource
- Ensures targetPath is preserved in all conversion paths
Test Plan
- Existing tests in
PomConstructionTestvalidate targetPath functionality and continue to pass - The
complete-modeltest resources contain targetPath examples that validate the fix - Manual testing with the provided reproduction case confirms the fix works
Backwards Compatibility
This fix restores full backwards compatibility with Maven 3.x behavior while preserving all ConnectedResource improvements introduced in rc-4.
Fixes #11062