gnodet opened a new pull request, #11394:
URL: https://github.com/apache/maven/pull/11394

   This PR fixes a regression in Maven 4 where resource `targetPath` was being 
resolved relative to the project base directory instead of the output directory 
(`target/classes` or `target/test-classes`).
   
   ## Problem
   
   In Maven 3.x, when a resource has a relative `targetPath`, it's resolved 
relative to the output directory. For example:
   
   ```xml
   <resource>
     <directory>${project.basedir}/rest</directory>
     <targetPath>target-dir</targetPath>
     <includes>
       <include>**/*.yml</include>
     </includes>
   </resource>
   ```
   
   In Maven 3.x, files would be copied to `target/classes/target-dir/`, but in 
Maven 4, they were being copied to `target-dir/` (relative to project root).
   
   ## Root Cause
   
   The bug was in the `DefaultSourceRoot` constructor that takes a `Resource` 
parameter. On line 172, the targetPath was being resolved as:
   ```java
   nonBlank(resource.getTargetPath()).map(baseDir::resolve).orElse(null)
   ```
   
   This resolves the targetPath relative to the base directory, not the output 
directory.
   
   ## Solution
   
   1. **Created a new constructor** in `DefaultSourceRoot.java` that accepts an 
`outputDir` parameter and correctly resolves targetPath relative to the output 
directory
   2. **Deprecated the old constructor** to maintain backward compatibility
   3. **Updated all call sites** to use the new constructor:
      - `DefaultProjectBuilder.java`
      - `ConnectedResource.java`
      - `MavenProject.java`
   4. **Updated unit tests** in `DefaultSourceRootTest.java` to verify the 
correct behavior
   5. **Created an integration test** 
`MavenITgh11381ResourceTargetPathTest.java` to verify the fix works end-to-end
   
   ## Testing
   
   The integration test verifies that:
   - Resources with relative `targetPath` are copied to the correct location 
under the output directory
   - The fix works for both main and test scopes
   
   Test results:
   ```
   Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
   ```
   
   Fixes #11381
   
   ---
   Pull Request opened by [Augment Code](https://www.augmentcode.com/) with 
guidance from the PR author


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to