You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "gnodet (via GitHub)" <gi...@apache.org> on 2026/06/18 05:19:47 UTC
[I] maven-resources-plugin NoSuchFileException when copying resources with targetPath [maven]
gnodet opened a new issue, #12306:
URL: https://github.com/apache/maven/issues/12306
## Description
Building `tomcat-taglibs-rdc` with Maven from the `maven-4.0.x` branch causes `maven-resources-plugin:3.3.1` to fail with a `NoSuchFileException` when copying resource files that use `<targetPath>`.
The same build succeeds with Maven 3.x.
## Error
```
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-resources-plugin:3.3.1:resources (default-resources)
on project taglibs-rdc:
copying .../src/main/resources/org/apache/taglibs/rdc/resources/RDCBundle_en_US.properties
to /org/apache/taglibs/rdc/resources/RDCBundle_en_US.properties
failed with NoSuchFileException -> [Help 1]
```
Note the target path starts with `/org/apache/...` — this appears to be a `<targetPath>` configuration in the resource definition. Maven 4 may be resolving the target path differently, causing the directory to not exist when the copy is attempted.
## Reproducer
```bash
git clone https://github.com/apache/tomcat-taglibs-rdc.git
cd tomcat-taglibs-rdc
mvn -B -e clean package -DskipTests
```
## Environment
- Maven: built from `maven-4.0.x` branch (bootstrapped with 4.0.0-rc-5)
- JDK: 17 (Temurin)
## Context
Found during [Maven 4 compatibility testing](https://github.com/gnodet/maven4-testing/issues/20677).
_Claude Code on behalf of Guillaume Nodet_
--
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: issues-unsubscribe@maven.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] maven-resources-plugin NoSuchFileException when copying resources with targetPath [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet closed issue #12306: maven-resources-plugin NoSuchFileException when copying resources with targetPath
URL: https://github.com/apache/maven/issues/12306
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] maven-resources-plugin NoSuchFileException when copying resources with targetPath [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on issue #12306:
URL: https://github.com/apache/maven/issues/12306#issuecomment-4738562108
## Root Cause Analysis: `<targetPath>.</targetPath>` → empty string → absolute path at filesystem root
### The triggering config in `taglibs-rdc/pom.xml`
```xml
<resource>
<directory>src/main/resources</directory>
<targetPath>.</targetPath> <!-- a literal dot -->
</resource>
```
### The bug chain (Maven 4 only)
1. **`DefaultSourceRoot.java:111`** — constructor normalizes targetPath via Java NIO:
```java
this.targetPathOrNull = (targetPathOrNull != null) ? targetPathOrNull.normalize() : null;
```
`Path.of(".").normalize()` returns an **empty path** (zero name elements, `toString()=""`) because `.` is a redundant element. The result is **not null**, so it gets stored as a non-null empty Path.
2. **`ConnectedResource.java:46`** — converts it to an empty string for the legacy plugin:
```java
.targetPath(sourceRoot.targetPath().map(Path::toString).orElse(null))
// → "" (empty string, NOT null)
```
3. **`DefaultMavenResourcesFiltering.getDestinationFile()`** — the plugin concatenates:
```java
destination = "" + "/" + "org/apache/taglibs/rdc/resources/RDCBundle_en_US.properties"
= "/org/apache/taglibs/rdc/resources/RDCBundle_en_US.properties" // absolute!
```
Java's `File("/org/...").isAbsolute() == true`, so `outputDirectory` (`/project/target/classes`) is **completely bypassed**. Maven tries to write to the filesystem root → `NoSuchFileException`.
### Why Maven 3 worked
Maven 3 passed the original `"."` string to the plugin without NIO normalization. The plugin computed `"." + "/" + filename = "./filename"` (relative), which was correctly resolved against the output directory.
### Fix location
**`DefaultSourceRoot.java:111`** — treat empty normalized paths as null (same semantics as no targetPath):
```java
if (targetPathOrNull != null) {
Path normalized = targetPathOrNull.normalize();
// "." normalizes to empty path = "copy to output root" = same as null
this.targetPathOrNull = (normalized.getNameCount() == 0) ? null : normalized;
} else {
this.targetPathOrNull = null;
}
```
The existing test `testHandlesEmptyTargetPathFromResource` tests explicit `""` (handled by `nonBlank()` → null, never reaches the normalization path), but **there's no test for `"."` which takes a completely different code path**. A test for `targetPath="."` would have caught this.
_Claude Code on behalf of Guillaume Nodet_
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org