apache/maven · error · IllegalArgumentException
source file does not exist or is not a file
Error message
source file does not exist or is not a file
What it means
Transport.put(Path source, URI relativeTarget) requires the source to be an existing regular file (Files.isRegularFile). Directories, non-existent paths, and symlinks whose target is missing are rejected with IllegalArgumentException before any network I/O starts, because the underlying PutTask uploads one concrete file.
Source
Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultTransport.java:102
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
@Override
public Optional<String> getString(URI relativeSource, Charset charset) {
requireNonNull(charset, "charset is null");
Optional<byte[]> data = getBytes(relativeSource);
return data.map(bytes -> new String(bytes, charset));
}
@Override
public void put(Path source, URI relativeTarget) {
requireNonNull(source, "source is null");
requireNonNull(relativeTarget, "relativeTarget is null");
if (!Files.isRegularFile(source)) {
throw new IllegalArgumentException("source file does not exist or is not a file");
}
if (relativeTarget.isAbsolute()) {
throw new IllegalArgumentException("Supplied URI is not relative");
}
URI target = baseURI.resolve(relativeTarget);
if (!target.toASCIIString().startsWith(baseURI.toASCIIString())) {
throw new IllegalArgumentException("Supplied relative URI escapes baseUrl");
}
PutTask putTask = new PutTask(target);
putTask.setDataPath(source);
try {
transporter.put(putTask);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
View on GitHub (pinned to e4093d4e12)
Solutions
- Ensure the file is fully written and the stream closed before calling put
- Guard the call with Files.isRegularFile(source) and fail fast with a clear message
- If you meant to publish a directory, package it into a file (jar/zip) first
Example fix
// before: file not created yet
Path jar = buildDir.resolve("app.jar");
transport.put(jar, URI.create("com/acme/app/1.0/app-1.0.jar"));
// after: build, flush, verify, then upload
Files.createDirectories(buildDir);
Files.write(jar, bytes);
if (!Files.isRegularFile(jar)) throw new IllegalStateException("artifact missing: " + jar);
transport.put(jar, URI.create("com/acme/app/1.0/app-1.0.jar")); Defensive patterns
Strategy: validation
Validate before calling
if (!Files.isRegularFile(source)) {
throw new IllegalStateException("upload source missing or not a file: " + source);
}
transport.put(source, relativeTarget); Prevention
- Close and flush whatever wrote the file before uploading
- In builds, put() only after the artifact-producing step completed
- Never pass directories; package directories into jar/zip files first
When it happens
Trigger: Calling put(tempPath, uri) before the file was created; passing a directory Path; passing a Path whose symlink target was deleted; mixing up the two arguments and passing the target directory as source.
Common situations: Deploying an artifact whose JAR has not been built yet due to build-order mistakes; uploading immediately after Files.createTempFile but before writing content plus close; passing the wrong variable (target instead of source).
Related errors
- Supplied URI is not relative
- Unknown resolver transport '{}'. Supported transports are: w
- Supplied relative URI escapes baseUrl
- Unsupported remote repository
- Error updating group repository metadata
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/7ad0eacf21165f0a.
Report an issue: GitHub.