Skip to content

Fix Source targetPath incorrectly aligned to project basedir#12178

Open
gnodet wants to merge 3 commits into
apache:masterfrom
gnodet:fix/resource-targetpath
Open

Fix Source targetPath incorrectly aligned to project basedir#12178
gnodet wants to merge 3 commits into
apache:masterfrom
gnodet:fix/resource-targetpath

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented May 28, 2026

Summary

  • DefaultModelPathTranslator.alignToBaseDirectory(Source) was incorrectly resolving Source.targetPath against the project basedir, turning a relative path like .grammar into an absolute path like /path/to/project/.grammar
  • This caused the maven-resources-plugin to write files to incorrect absolute locations instead of relative to the output directory (target/classes)
  • Removed the targetPath alignment from Source path translation, matching the existing behavior for Resource.targetPath (which is correctly not aligned)

Test plan

  • New DefaultModelPathTranslatorTest — verifies Source targetPath is NOT aligned while directory IS aligned
  • New ProjectBuilderTest#testSourceTargetPathRemainsRelative — full model builder integration test with .grammar and META-INF/test targetPaths, verifying both SourceRoot API and compat Resource API
  • Existing PomConstructionTest#testTargetPathResourceRegression — still passes
  • Existing ResourceIncludeTest (10 tests) — still passes
  • Existing DefaultSourceRootTest (13 tests) — still passes
  • Full test suite for maven-impl and maven-core (547 tests) — all pass

Claude Code on behalf of Guillaume Nodet

🤖 Generated with Claude Code

DefaultModelPathTranslator.alignToBaseDirectory(Source) was resolving
Source.targetPath against the project basedir, turning a relative path
like ".grammar" into an absolute path like "/path/to/project/.grammar".
This caused the maven-resources-plugin to write files to incorrect
absolute locations instead of relative to the output directory
(target/classes).

The targetPath should remain relative to the output directory, matching
the behavior documented in maven.mdo and consistent with how
Resource.targetPath is handled (not aligned to basedir).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gnodet added a commit that referenced this pull request May 28, 2026
Cherry-pick from fix/resource-targetpath branch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet added this to the 4.0.0-rc-6 milestone May 28, 2026
gnodet and others added 2 commits May 28, 2026 17:17
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use Path.endsWith(Path) instead of String.endsWith(String) to handle
both / and \ separators cross-platform.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet requested a review from desruisseaux May 29, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant