GoogleContainerTools/jib · error · NoSuchFileException
NoSuchFileException: <directory>
Error message
NoSuchFileException: <directory>
What it means
JavaContainerBuilder.addDirectory requires the directory passed to exist on the local filesystem. Before adding the directory to the build, it calls Files.exists(); if the path does not exist it throws NoSuchFileException with the directory path. This is a fail-fast check so users get a clear error about a missing resources/classes/dependencies directory rather than a silently incomplete image.
Source
Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/api/JavaContainerBuilder.java:680
}
String classpathString = String.join(":", classpathElements);
List<String> entrypoint = new ArrayList<>(4 + jvmFlags.size());
entrypoint.add("java");
entrypoint.addAll(jvmFlags);
entrypoint.add("-cp");
entrypoint.add(classpathString);
entrypoint.add(mainClass);
jibContainerBuilder.setEntrypoint(entrypoint);
}
return jibContainerBuilder;
}
private JavaContainerBuilder addDirectory(
List<PathPredicatePair> addedPaths, Path directory, Predicate<Path> filter)
throws NoSuchFileException, NotDirectoryException {
if (!Files.exists(directory)) {
throw new NoSuchFileException(directory.toString());
}
if (!Files.isDirectory(directory)) {
throw new NotDirectoryException(directory.toString());
}
addedPaths.add(new PathPredicatePair(directory, filter));
return this;
}
private void addFileToLayer(
Map<LayerType, FileEntriesLayer.Builder> layerBuilders,
LayerType layerType,
Path sourceFile,
AbsoluteUnixPath pathInContainer) {
if (!layerBuilders.containsKey(layerType)) {
layerBuilders.put(layerType, FileEntriesLayer.builder());
}
Instant modificationTime = modificationTimeProvider.get(sourceFile, pathInContainer);
layerBuilders.get(layerType).addEntry(sourceFile, pathInContainer, modificationTime);View on GitHub (pinned to fb949e2676)
Solutions
- Verify the directory exists at the path you pass before calling jib: Files.isDirectory(path) or ls the path.
- Create the directory if your build legitimately produces it later: Files.createDirectories(resourcesDir) before calling addResources.
- Fix the path - use correct project root, e.g. Paths.get("src/main/resources") relative to the module, and check for typos/case.
- Ensure your compile step runs before jib builds, so target/classes or build/classes exists.
- If you intend to add a single file instead, use addFileToLayer-style APIs rather than a directory path.
Example fix
// before
JavaContainerBuilder.builder().addResources(Paths.get("src/main/resourcs"));
// after
Path res = Paths.get("src/main/resources");
if (!Files.isDirectory(res)) { throw new IllegalStateException("missing resources dir: " + res); }
JavaContainerBuilder.builder().addResources(res); Defensive patterns
Strategy: validation
Validate before calling
if (!Files.isDirectory(dir)) throw new IllegalArgumentException("Missing directory: " + dir); Type guard
boolean isUsableDir(Path p) { return p != null && Files.isDirectory(p); } Try / catch
try { builder.addResources(dir); } catch (NoSuchFileException e) { log.error("Directory not found: {}", e.getFile()); throw new BuildSetupException(e); } Prevention
- Assert directory existence in an init step before configuring jib
- Run compilation before jib so output directories exist
- Use build-tool-provided paths (sourceSets.main.output) instead of hardcoded strings
- Add Files.createDirectories for directories your build owns
When it happens
Trigger: Calling addResources(Path), addClasses(Path), addDependencies(Path) (or addDirectory directly) with a Path that does not exist on disk, e.g. a typo'd path or a directory created only by a later build phase.
Common situations: Pointing addResources at src/main/resources when the module was never built or the folder was cleaned; using a wrong project root in multi-module builds; running jib before the classes output directory (target/classes, build/classes) exists because no compilation ran; path spelled with wrong case or separator.
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
- NotDirectoryException: <directory>
- Cannot create FileLayers from non-file, non-directory: ${src
- Unable to create cache directory for project path: ${path} -
- ${src} is not a parent of ${path}
- Check the full stace trace, and if the root cause is from AS
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/055624f41a3f0c49.
Report an issue: GitHub.