-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix resource targetPath resolution to be relative to output directory (fixes #11381) #11394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gnodet
merged 10 commits into
apache:master
from
gnodet:fix-gh-11381-resource-targetpath
Nov 7, 2025
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eb23cfc
[GH-11381] Fix resource targetPath resolution to be relative to outpu…
gnodet b64a8d5
Fix ConnectedResource to handle null output directories and compute r…
gnodet e6ba7cf
Simplify targetPath handling by keeping it as relative path
gnodet 2b154b2
Remove unnecessary outputDir parameter from MavenProject and DefaultP…
gnodet 708e059
Fix resource targetPath handling according to PR feedback
gnodet c747855
Fix GH-11381: Ensure resource targetPath is relative to output directory
gnodet 642e43b
Improve SourceRoot javadoc to clarify targetPath behavior
gnodet da122e1
Simplify
gnodet 10734c5
Enhance javadoc for SourceRoot.targetPath() and Project.getOutputDire…
gnodet e14828b
Further refine Maven 4 API javadoc for explicit clarity
gnodet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11381ResourceTargetPathTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.it; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * This is a test set for <a href="https://github.com/apache/maven/issues/11381">GH-11381</a>. | ||
| * | ||
| * Verifies that relative targetPath in resources is resolved relative to the output directory | ||
| * (target/classes) and not relative to the project base directory, maintaining Maven 3.x behavior. | ||
| * | ||
| * @since 4.0.0-rc-4 | ||
| */ | ||
| class MavenITgh11381ResourceTargetPathTest extends AbstractMavenIntegrationTestCase { | ||
|
|
||
| /** | ||
| * Verify that resources with relative targetPath are copied to target/classes/targetPath | ||
| * and not to the project root directory. | ||
| * | ||
| * @throws Exception in case of failure | ||
| */ | ||
| @Test | ||
| void testRelativeTargetPathInResources() throws Exception { | ||
| File testDir = extractResources("/gh-11381"); | ||
|
|
||
| Verifier verifier = newVerifier(testDir.getAbsolutePath()); | ||
| verifier.setAutoclean(false); | ||
| verifier.deleteDirectory("target"); | ||
| verifier.addCliArgument("process-resources"); | ||
| verifier.execute(); | ||
| verifier.verifyErrorFreeLog(); | ||
|
|
||
| // Verify that resources were copied to target/classes/target-dir (Maven 3.x behavior) | ||
| verifier.verifyFilePresent("target/classes/target-dir/test.yml"); | ||
| verifier.verifyFilePresent("target/classes/target-dir/subdir/another.yml"); | ||
|
|
||
| // Verify that resources were NOT copied to the project root target-dir directory | ||
| verifier.verifyFileNotPresent("target-dir/test.yml"); | ||
| verifier.verifyFileNotPresent("target-dir/subdir/another.yml"); | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.apache.maven.its.gh11381</groupId> | ||
| <artifactId>test</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <name>Maven Integration Test :: GH-11381</name> | ||
| <description>Test for relative targetPath in resources - should be relative to output directory</description> | ||
|
|
||
| <build> | ||
| <resources> | ||
| <resource> | ||
| <directory>${project.basedir}/rest</directory> | ||
| <targetPath>target-dir</targetPath> | ||
| <includes> | ||
| <include>**/*.yml</include> | ||
| </includes> | ||
| </resource> | ||
| </resources> | ||
| </build> | ||
| </project> | ||
|
|
4 changes: 4 additions & 0 deletions
4
its/core-it-suite/src/test/resources/gh-11381/rest/subdir/another.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Another test YAML file for GH-11381 | ||
| another: | ||
| test: data | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Test YAML file for GH-11381 | ||
| test: | ||
| key: value | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it was a bug. The specification that we wrote in
maven.mdosaid thattargetPathshall be relative to the target directory. Fixing that bug was the subject of #11322, but that correction was incomplete. We could said that this pull request #11394 completes #11322.