GoogleContainerTools/jib · error · IllegalStateException

<field1>, <field2>, ... and <fieldN> are required but not se

Error message

<field1>, <field2>, ... and <fieldN> are required but not set

What it means

Same BuildContext.Builder.build() validation as the 1-2 field case, but for three or more missing required fields. The code joins the field names with commas and 'and' before the last one, then throws IllegalStateException with '<field1>, <field2>, ... and <fieldN> are required but not set'.

Source

Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/configuration/BuildContext.java:361

              executorService == null, // shutDownExecutorService
              alwaysCacheBaseImage,
              registryMirrors,
              enablePlatformTags);

        case 1:
          throw new IllegalStateException(missingFields.get(0) + " is required but not set");

        case 2:
          throw new IllegalStateException(
              missingFields.get(0) + " and " + missingFields.get(1) + " are required but not set");

        default:
          missingFields.add("and " + missingFields.remove(missingFields.size() - 1));
          StringJoiner errorMessage = new StringJoiner(", ", "", " are required but not set");
          for (String missingField : missingFields) {
            errorMessage.add(missingField);
          }
          throw new IllegalStateException(errorMessage.toString());
      }
    }

    @Nullable
    @VisibleForTesting
    Path getBaseImageLayersCacheDirectory() {
      return baseImageLayersCacheDirectory;
    }

    @Nullable
    @VisibleForTesting
    Path getApplicationLayersCacheDirectory() {
      return applicationLayersCacheDirectory;
    }
  }

  /**
   * Creates a new {@link Builder} to build a {@link BuildContext}.

View on GitHub (pinned to fb949e2676)

Solutions

  1. Call every required setter listed in the message on the builder before build()
  2. Compare against a known-good BuildContext construction (or the Maven/Gradle plugin setup) to see which fields you skipped
  3. Fail fast in your own code: check config completeness before creating the builder

Example fix

// before
BuildContext ctx = BuildContext.builder().build(); // throws with many fields
// after
BuildContext ctx = BuildContext.builder()
    .setBaseImage(...)
    .setTargetImage(...)
    .setContainerConfiguration(...)
    .setLayerConfigurations(...)
    .build();
Defensive patterns

Strategy: validation

Validate before calling

// Validate your source config object before building the context
Objects.requireNonNull(cfg.getBaseImage(), "baseImage required");
Objects.requireNonNull(cfg.getTargetImage(), "targetImage required");
Objects.requireNonNull(cfg.getLayers(), "layers required");
BuildContext ctx = BuildContext.builder()
    .setBaseImage(cfg.getBaseImage())
    .setTargetImage(cfg.getTargetImage())
    .setLayerConfigurations(cfg.getLayers())
    .build();

Prevention

When it happens

Trigger: Calling build() on a nearly-empty BuildContext.Builder — e.g. a freshly created builder with few or no setters called, so 3+ required fields (base image, target image, container config, etc.) are unset.

Common situations: Initial scaffolding of jib-core based builds where the builder is only partially wired up, or conditional code paths that skip most setters when config sections are absent.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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