GoogleContainerTools/jib · error · UnsupportedOperationException
Cannot create FileLayers from non-file, non-directory: ${src
Error message
Cannot create FileLayers from non-file, non-directory: ${src} What it means
When converting FileLayerSpec copy directives into layer entries, Layers.toLayers resolves each src (relative to buildRoot) and requires it to be either a directory or a regular file. If Files.isDirectory and Files.isRegularFile both fail (missing path, broken symlink, special file), it throws UnsupportedOperationException naming the src.
Source
Thrown at jib-cli/src/main/java/com/google/cloud/tools/jib/cli/buildfile/Layers.java:82
// each loop is a new layer
if (entry instanceof FileLayerSpec) {
FileEntriesLayer.Builder layerBuiler = FileEntriesLayer.builder();
FileLayerSpec fileLayer = (FileLayerSpec) entry;
layerBuiler.setName(fileLayer.getName());
// layer properties
fileLayer.getProperties().ifPresent(filePropertiesStack::push);
for (CopySpec copySpec : ((FileLayerSpec) entry).getFiles()) {
// copy spec properties
copySpec.getProperties().ifPresent(filePropertiesStack::push);
// relativize all paths to the buildRoot location
Path rawSrc = copySpec.getSrc();
Path src = rawSrc.isAbsolute() ? rawSrc : buildRoot.resolve(rawSrc);
AbsoluteUnixPath dest = copySpec.getDest();
if (!Files.isDirectory(src) && !Files.isRegularFile(src)) {
throw new UnsupportedOperationException(
"Cannot create FileLayers from non-file, non-directory: " + src.toString());
}
if (Files.isRegularFile(src)) { // regular file
if (!copySpec.getExcludes().isEmpty() || !copySpec.getIncludes().isEmpty()) {
throw new UnsupportedOperationException(
"Cannot apply includes/excludes on single file copy directives.");
}
layerBuiler.addEntry(
src,
copySpec.isDestEndsWithSlash() ? dest.resolve(src.getFileName()) : dest,
filePropertiesStack.getFilePermissions(),
filePropertiesStack.getModificationTime(),
filePropertiesStack.getOwnership());
} else if (Files.isDirectory(src)) { // directory
List<PathMatcher> excludes =
copySpec.getExcludes().stream()
.map(Layers::toPathMatcher)
.collect(Collectors.toList());View on GitHub (pinned to fb949e2676)
Solutions
- Verify the src path exists relative to the build root (or make it absolute).
- Run the build step that produces the file/directory before Jib.
- Fix or remove dangling symlinks in the copied tree.
- Check that the build root (-Djib.alwaysCacheWorkDir / build context dir) is the directory you expect.
Example fix
// before
{"name": "app", "files": [{"src": "target/app.jar", "dest": "/app"}]} // jar not built
// after
mvn package && jib ... // ensure target/app.jar exists first Defensive patterns
Strategy: validation
Validate before calling
Path src = buildRoot.resolve(copySpec.getSrc());
if (!Files.isDirectory(src) && !Files.isRegularFile(src)) {
throw new IllegalStateException("Copy src does not exist: " + src);
} Try / catch
try {
jibBuild();
} catch (UnsupportedOperationException e) {
if (e.getMessage().startsWith("Cannot create FileLayers from non-file, non-directory")) {
log.error("Check src paths in build file relative to build root: {}", e.getMessage());
} else throw e;
} Prevention
- Verify all copy src paths exist before running Jib
- Run artifact-producing build steps first
- Run Jib from the expected working directory
- Clean dangling symlinks from the source tree
When it happens
Trigger: A copy spec's src path does not exist relative to the build root, points to a broken symlink, or is a special file (socket, device, fifo).
Common situations: Typos in src paths, running the CLI from the wrong working directory so relative srcs don't resolve, artifacts not yet built, dangling symlinks in the source tree.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- ${src} is not a parent of ${path}
- NoSuchFileException: <directory>
- NotDirectoryException: <directory>
- Unable to create cache directory for project path: ${path} -
- Could not parse layer entry, missing required property 'name
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/fae28a4b488c6021.
Report an issue: GitHub.