GoogleContainerTools/jib · error · GradleException

Both 'bootJar' and 'jar' tasks are enabled, but they write t

Error message

Both 'bootJar' and 'jar' tasks are enabled, but they write their jar file into the same location at ${jarPath}. Did you forget to set 'archiveClassifier' on either task?

What it means

When the Spring Boot plugin is present, Jib checks that the bootJar and jar tasks do not write to the same output path. If both are enabled and their output jars collide, Jib cannot tell which jar to containerize and throws GradleException, suggesting the user set a distinct archiveClassifier.

Source

Thrown at jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibPlugin.java:173

            if (bootWarTask != null) {
              jibDependencies.add(bootWarTask);
            }
          } else if ("packaged".equals(jibExtension.getContainerizingMode())) {
            // Have all tasks depend on the 'jar' task.
            TaskProvider<Task> jarTask = projectAfterEvaluation.getTasks().named("jar");
            jibDependencies.add(jarTask);

            if (projectAfterEvaluation.getPlugins().hasPlugin("org.springframework.boot")) {
              Task bootJarTask = projectAfterEvaluation.getTasks().getByName("bootJar");

              if (bootJarTask.getEnabled()) {
                String bootJarPath = bootJarTask.getOutputs().getFiles().getAsPath();
                String jarPath = jarTask.get().getOutputs().getFiles().getAsPath();
                if (bootJarPath.equals(jarPath)) {
                  if (!jarTask.get().getEnabled()) {
                    ((Jar) jarTask.get()).getArchiveClassifier().set("original");
                  } else {
                    throw new GradleException(
                        "Both 'bootJar' and 'jar' tasks are enabled, but they write their jar file "
                            + "into the same location at "
                            + jarPath
                            + ". Did you forget to set 'archiveClassifier' on either task?");
                  }
                }
              }
              jarTask.get().setEnabled(true);
            }
          }

          SourceSet mainSourceSet =
              projectAfterEvaluation
                  .getExtensions()
                  .getByType(SourceSetContainer.class)
                  .getByName(SourceSet.MAIN_SOURCE_SET_NAME);
          jibDependencies.add(mainSourceSet.getRuntimeClasspath());
          jibDependencies.add(

View on GitHub (pinned to fb949e2676)

Solutions

  1. Set a distinct archiveClassifier on the plain jar task: `jar { archiveClassifier.set('plain') }` or bootJar `archiveClassifier.set('boot')`
  2. Disable the plain jar task if only the boot jar is needed: `jar { enabled = false }` (Jib then auto-sets classifier 'original' if needed)
  3. Ensure only one of the two tasks writes to the same destination path
  4. Pin a Jib version compatible with your Spring Boot version's default jar naming

Example fix

// before
tasks.jar { enabled = true } // same path as bootJar
// after
tasks.jar {
  archiveClassifier.set('plain')
}
Defensive patterns

Strategy: validation

Validate before calling

def bootJar = tasks.findByName('bootJar'), jar = tasks.findByName('jar')
if (bootJar && jar && jar.enabled && bootJar.enabled &&
    bootJar.outputs.files.asPath == jar.outputs.files.asPath) {
  jar.archiveClassifier.set('plain')
  logger.lifecycle('Set archiveClassifier=plain on jar to avoid Jib bootJar/jar conflict')
}

Try / catch

try {
  jib.build()
} catch (GradleException e) {
  if (e.message.contains("Both 'bootJar' and 'jar' tasks are enabled")) {
    logger.error('Set distinct archiveClassifier or disable the plain jar task')
  } else { throw e }
}

Prevention

When it happens

Trigger: Applying both com.google.cloud.tools.jib and Spring Boot's plugin where bootJar and jar tasks are both enabled and produce jars at the same path (bootJarPath.equals(jarPath)) and the plain jar task is not disabled; triggered during Jib task execution's afterEvaluate/action hook.

Common situations: Spring Boot 2.5+ projects where jar and bootJar both build <name>-<version>.jar unless archiveClassifier is set; upgrading Spring Boot after which Jib's older workaround (disabling jar) no longer applies; custom jar task configuration overriding archiveClassifier.

Related errors


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