Skip to content

Conversation

@mbaurin
Copy link
Contributor

@mbaurin mbaurin commented Aug 24, 2025

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 verify to 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.

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

  1. 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)
  2. Fixed DefaultSourceRoot constructor (DefaultSourceRoot.java:120-121)

    • Replaced hardcoded targetPath = null with proper Resource extraction
    • Added value = nonBlank(resource.getTargetPath()); targetPath = (value != null) ? baseDir.resolve(value) : null;
  3. 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 PomConstructionTest validate targetPath functionality and continue to pass
  • The complete-model test 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

@slawekjaranowski slawekjaranowski added the bug Something isn't working label Aug 24, 2025
@slawekjaranowski
Copy link
Member

@mbaurin thank, please also adjust tests as you describe

@mbaurin
Copy link
Contributor Author

mbaurin commented Aug 25, 2025

@mbaurin thank, please also adjust tests as you describe

done ✅ @slawekjaranowski

@gnodet gnodet changed the title [MNG-11062] Fix targetPath parameter ignored in resource bundles Fix targetPath parameter ignored in resource bundles (fixes #11062) Aug 27, 2025
@gnodet gnodet force-pushed the fix/maven-4-targetpath-resource-bundle-ignored branch from a1760ab to f4fa892 Compare August 27, 2025 16:33
@gnodet gnodet merged commit e4579e9 into apache:master Aug 29, 2025
19 checks passed
@github-actions github-actions bot added this to the 4.1.0 milestone Aug 29, 2025
gnodet added a commit to gnodet/maven that referenced this pull request Aug 29, 2025
) (apache#11063)

Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
(cherry picked from commit e4579e9)
@gnodet
Copy link
Contributor

gnodet commented Aug 29, 2025

💚 All backports created successfully

Status Branch Result
maven-4.0.x

Questions ?

Please refer to the Backport tool documentation

gnodet added a commit that referenced this pull request Aug 29, 2025
…11063) (#11080)

(cherry picked from commit e4579e9)

Co-authored-by: Mathieu Baurin <86267428+mbaurin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.0.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

targetPath parameter in resource bundle ignored

4 participants