GoogleContainerTools/jib · error · NoSuchFileException

${file}

Error message

${file}

What it means

JavaContainerBuilder.addDependencies checks that every path in the dependency list exists before adding any of them, throwing NoSuchFileException (an IOException) naming the missing file. It fails fast so you never build an image with a half-registered dependency list.

Source

Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/api/JavaContainerBuilder.java:301

   */
  public JavaContainerBuilder setOthersDestination(RelativeUnixPath othersDestination) {
    this.othersDestination = othersDestination;
    return this;
  }

  /**
   * Adds dependency JARs to the image. Duplicate JAR filenames across all dependencies are renamed
   * with the filesize in order to avoid collisions.
   *
   * @param dependencyFiles the list of dependency JARs to add to the image
   * @return this
   * @throws IOException if adding the layer fails
   */
  public JavaContainerBuilder addDependencies(List<Path> dependencyFiles) throws IOException {
    // Make sure all files exist before adding any
    for (Path file : dependencyFiles) {
      if (!Files.exists(file)) {
        throw new NoSuchFileException(file.toString());
      }
    }
    addedDependencies.addAll(dependencyFiles);
    classpathOrder.add(LayerType.DEPENDENCIES);
    return this;
  }

  /**
   * Adds dependency JARs to the image. Duplicate JAR filenames across all dependencies are renamed
   * with the filesize in order to avoid collisions.
   *
   * @param dependencyFiles the list of dependency JARs to add to the image
   * @return this
   * @throws IOException if adding the layer fails
   */
  public JavaContainerBuilder addDependencies(Path... dependencyFiles) throws IOException {
    return addDependencies(Arrays.asList(dependencyFiles));
  }

View on GitHub (pinned to fb949e2676)

Solutions

  1. Verify each path exists (Files.exists) before calling addDependencies
  2. Convert relative paths to absolute against the correct base directory
  3. Rebuild/refresh the dependency list so it reflects current artifacts
  4. Catch NoSuchFileException and report which dependency file is missing

Example fix

// before
javaContainerBuilder.addDependencies(dependencyFiles);
// after
List<Path> existing = dependencyFiles.stream().filter(Files::exists).collect(Collectors.toList());
javaContainerBuilder.addDependencies(existing);
Defensive patterns

Strategy: validation

Validate before calling

List<Path> missing = dependencyFiles.stream().filter(p -> !Files.exists(p)).collect(Collectors.toList()); if (!missing.isEmpty()) throw new IllegalStateException("Missing deps: " + missing);

Type guard

Predicate<Path> exists = p -> p != null && Files.exists(p);

Try / catch

try { builder.addDependencies(files); } catch (NoSuchFileException e) { log.error("Dependency file missing: {}", e.getFile()); }

Prevention

When it happens

Trigger: Calling addDependencies with a List<Path> containing a file that does not exist on disk — a path with a typo, a file deleted before the build, or a path relative to the wrong working directory.

Common situations: Maven/Gradle plugins passing resolved artifact paths that were cleaned; scripts building the dependency list with stale or wrong-relative paths; files removed between collection and container build.

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


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/54919a4dc139bfba. Report an issue: GitHub.