Skip to content

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Nov 7, 2025

Backport

This will backport the following commits from master to maven-4.0.x:

Questions ?

Please refer to the Backport tool documentation

…fixes apache#11381) (apache#11394)

This commit fixes the regression where resources with a relative targetPath
were being copied to the project root instead of relative to the output
directory (target/classes or target/test-classes).

Changes:

1. DefaultSourceRoot.fromModel: Store targetPath as a relative path instead
   of resolving it against baseDir and outputDir. This ensures that
   SourceRoot.targetPath() returns a relative path as intended by the
   Maven 4 API javadoc.

2. ConnectedResource.computeRelativeTargetPath: Simplified to directly
   return the relative targetPath from SourceRoot, since it's now always
   stored as relative.

3. Updated tests to expect relative paths from SourceRoot.targetPath().

Maven 4 API Conformance:
- SourceRoot.targetPath() returns an Optional<Path> containing the explicit
  target path, which should be relative to the output directory (or absolute
  if explicitly specified as absolute).
- SourceRoot.targetPath(Project) resolves this relative path against the
  project's output directory to produce an absolute path.

Maven 3 Compatibility:
- Resource.getTargetPath() in Maven 3 was always relative to the output
  directory. This behavior is preserved by storing targetPath as relative
  in SourceRoot and converting it back to relative for the Resource API
  via ConnectedResource.

Example: With <targetPath>custom-dir</targetPath>:
- Maven 3: Resources copied to target/classes/custom-dir
- Maven 4 (before fix): Resources copied to project-root/custom-dir
- Maven 4 (after fix): Resources copied to target/classes/custom-dir

Fixes apache#11381

(cherry picked from commit 9b95526)
@gnodet gnodet force-pushed the backport/maven-4.0.x/pr-11394 branch from f6c0427 to 18ac79f Compare November 7, 2025 13:12
@gnodet gnodet added bug Something isn't working backport mvn40 labels Nov 7, 2025
@gnodet gnodet merged commit c628d02 into apache:maven-4.0.x Nov 7, 2025
22 checks passed
@github-actions github-actions bot added this to the 4.0.0 milestone Nov 7, 2025
@gnodet gnodet deleted the backport/maven-4.0.x/pr-11394 branch November 14, 2025 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Something isn't working mvn40

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant