spring-projects/spring-boot · error · GradleException

Failed to create {}

Error message

Failed to create {}

What it means

Thrown by BootZipCopyAction.execute() when writeArchive() raises IOException while creating the boot archive (jar/war), wrapped as GradleException with the target output file. This is the top-level failure for any IO problem during the initial creation/opening of the archive output stream or its overall write.

Source

Thrown at build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java:143

		this.includeDefaultLoader = includeDefaultLoader;
		this.jarmodeToolsLocation = jarmodeToolsLocation;
		this.requiresUnpack = requiresUnpack;
		this.exclusions = exclusions;
		this.librarySpec = librarySpec;
		this.compressionResolver = compressionResolver;
		this.encoding = encoding;
		this.resolvedDependencies = resolvedDependencies;
		this.layerResolver = layerResolver;
	}

	@Override
	public WorkResult execute(CopyActionProcessingStream copyActions) {
		try {
			writeArchive(copyActions);
			return WorkResults.didWork(true);
		}
		catch (IOException ex) {
			throw new GradleException("Failed to create " + this.output, ex);
		}
	}

	private void writeArchive(CopyActionProcessingStream copyActions) throws IOException {
		OutputStream output = new FileOutputStream(this.output);
		try {
			writeArchive(copyActions, output);
		}
		finally {
			closeQuietly(output);
		}
	}

	private void writeArchive(CopyActionProcessingStream copyActions, OutputStream output) throws IOException {
		ZipArchiveOutputStream zipOutput = new ZipArchiveOutputStream(output);
		try {
			setEncodingIfNecessary(zipOutput);
			Processor processor = new Processor(zipOutput);

View on GitHub (pinned to 5b2dbdbb8b)

Solutions

  1. Confirm the output directory exists and is writable, and that the target jar is not open elsewhere.
  2. Free disk space / inodes on the build volume.
  3. Run ./gradlew clean to remove a possibly half-written/corrupt output.
  4. On Windows, close IDEs/agents that may lock build/libs/*.jar, or add the dir to antivirus exclusions.

Example fix

// shell: ensure clean, writable output
//   ./gradlew clean bootJar --info
// build.gradle.kts: redirect output if needed
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootJar>('bootJar') {
    archiveFileName.set('app.jar')
    destinationDirectory.set(layout.buildDirectory.dir('libs'))
}
Defensive patterns

Strategy: try-catch

Validate before calling

import java.io.File
val outDir = layout.buildDirectory.dir("libs").get().asFile
if (!outDir.exists() && !outDir.mkdirs()) {
    throw GradleException("Cannot create output dir ${outDir.absolutePath}")
}
if (!outDir.canWrite()) {
    throw GradleException("Output dir ${outDir.absolutePath} is not writable")
}

Try / catch

try {
    tasks.named("bootJar").get().actions
    gradle.taskGraph.whenReady { /* run */ }
} catch (ex: org.gradle.api.GradleException) {
    if (ex.message?.startsWith("Failed to create ") == true) {
        logger.error("Cannot write the archive. Check disk space, permissions, and file locks.")
    }
    throw ex
}

Prevention

When it happens

Trigger: bootJar/bootWar runs BootZipCopyAction.execute(); writeArchive() opens a FileOutputStream on this.output and streams entries; any IOException (cannot create file, permission denied, no space, parent missing, read-only FS) propagates to line 143.

Common situations: Disk full; output directory not writable; the target jar is locked by another process (IDE/Windows); build directory on a read-only or network filesystem; path too long; antivirus interference; out of inodes.

Related errors


AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04). Data as JSON: /data/errors/92fe4e2eda055351.json. Report an issue: GitHub.