gnodet opened a new pull request, #12307:
URL: https://github.com/apache/maven/pull/12307
## Problem
When a resource is declared with `<targetPath>.</targetPath>`, Maven 4
throws a `NoSuchFileException`. Closes #12306.
## Root Cause
In `DefaultSourceRoot`'s canonical constructor, the incoming
`targetPathOrNull` was normalized via `Path.normalize()` and stored as-is. On
JDK 21 (Linux), `Path.of(".").normalize()` returns a `Path` whose `toString()`
is `""` (empty string) but whose `getNameCount()` is `1`. This empty-string
path was then passed to plugins, which concatenated it into an absolute path
like `/org/apache/…`, bypassing the output directory entirely and causing
`NoSuchFileException`.
## Fix
After normalizing the target path, treat any path whose `toString()` is
empty (which includes `"."` after normalization) the same as a null/absent
target path. This preserves the Maven 3.x behavior where
`<targetPath>.</targetPath>` is equivalent to not specifying a `targetPath`.
## Changes
-
`impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java` —
normalize-and-nullify logic
-
`impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSourceRootTest.java`
— two new tests:
- `testHandlesDotTargetPathFromResource` — verifies `"."` is treated as
absent
- `testHandlesDotRelativeTargetPathFromResource` — verifies `"./subdir"`
normalizes to `"subdir"` and is preserved
## Test plan
- [ ] `mvn -pl impl/maven-impl -am clean test -DskipITs -Drat.skip=true`
passes (453 tests, 0 failures)
- [ ] New tests `testHandlesDotTargetPathFromResource` and
`testHandlesDotRelativeTargetPathFromResource` pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]