spring-projects/spring-boot · error · ReportableException
File '{}' already exists. Use --force if you want to overwri
Error message
File '{}' already exists. Use --force if you want to overwrite or specify an alternate location. What it means
Thrown by ProjectGenerator.writeProject when the single-file output target already exists and --force was not supplied. Unlike [93] (per-entry during extraction), this guards the top-level output file path used when writing the project as a single archive.
Source
Thrown at cli/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/init/ProjectGenerator.java:143
+ "' already exists. Use --force if you want to overwrite or "
+ "specify an alternate location.");
}
if (!entry.isDirectory()) {
FileCopyUtils.copy(StreamUtils.nonClosing(zipStream), new FileOutputStream(file));
}
else {
file.mkdir();
}
zipStream.closeEntry();
entry = zipStream.getNextEntry();
}
}
private void writeProject(ProjectGenerationResponse entity, String output, boolean overwrite) throws IOException {
File outputFile = new File(System.getProperty("user.dir"), output);
if (outputFile.exists()) {
if (!overwrite) {
throw new ReportableException(
"File '" + outputFile.getName() + "' already exists. Use --force if you want to "
+ "overwrite or specify an alternate location.");
}
if (!outputFile.delete()) {
throw new ReportableException("Failed to delete existing file " + outputFile.getPath());
}
}
byte[] content = entity.getContent();
Assert.state(content != null, "'content' must not be null");
FileCopyUtils.copy(content, outputFile);
Log.info("Content saved to '" + output + "'");
}
private void fixExecutableFlag(File dir, String fileName) {
File f = new File(dir, fileName);
if (f.exists()) {
f.setExecutable(true, false);
}View on GitHub (pinned to 270dfe353f)
Solutions
- Pass --force to overwrite the file
- Choose a different --output file name
- Delete or rename the existing file first
Example fix
// before $ spring init --output app.zip # app.zip exists // after $ spring init --output app.zip --force
Defensive patterns
Strategy: validation
Validate before calling
// Before writing, check the output file and decide explicitly.
java.io.File out = new java.io.File(System.getProperty("user.dir"), request.getOutput());
if (out.exists() && !force) {
throw new IllegalStateException(
"Output exists: " + out + " - pass --force or pick another name");
} Try / catch
try {
generator.generateProject(request, force);
} catch (ReportableException ex) {
if (ex.getMessage().startsWith("File '") && ex.getMessage().contains("already exists")) {
Log.error("Output file exists - rerun with --force or a different --output");
}
throw ex;
} Prevention
- Use a unique --output name per run (timestamp, project name)
- Pass --force only when overwriting intentionally
- Clean stale output files in CI between runs
When it happens
Trigger: Writing the project to a file (no --extract) whose path already exists, without --force.
Common situations: Re-running 'spring init --output app.zip' twice; the output file name collides with a pre-existing file.
Related errors
- {} '{}' already exists. Use --force if you want to overwrite
- Could not save the project, the server did not set a preferr
- Invalid service URL ({})
- No project type with id '{}' - check the service capabilitie
- No type found with build '{}' and format '{}' check the serv
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/c286cd2c5ccac5ad.
Report an issue: GitHub.