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:

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

Backwards Compatibility

This fix restores full backwards compatibility with Maven 3.x behavior while preserving all ConnectedResource improvements introduced in rc-4.

Fixes #11062