quarkusio/quarkus · error · CodestartStructureException
Target file already exists: + targetPath.toString()
Error message
Target file already exists: + targetPath.toString()
What it means
checkTargetDoesNotExist is a fail-fast guard for strategy handlers that must not overwrite files. It throws when the resolved target path already exists on disk. This prevents strategies like 'create-new' from silently clobbering user files.
Source
Thrown at independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/CodestartFileStrategyHandler.java:47
new SmartPomMergeCodestartFileStrategyHandler(),
new SmartPackageFileStrategyHandler(),
new DockerComposeCodestartFileStrategyHandler())
.collect(Collectors.toMap(CodestartFileStrategyHandler::name, Function.identity()));
String name();
void process(Path targetDirectory, String relativePath, List<TargetFile> codestartFiles, Map<String, Object> data)
throws IOException;
default void checkNotEmptyCodestartFiles(List<TargetFile> codestartFiles) {
if (codestartFiles == null || codestartFiles.isEmpty()) {
throw new CodestartStructureException("codestartFiles must not be null or empty");
}
}
default void checkTargetDoesNotExist(Path targetPath) {
if (Files.exists(targetPath)) {
throw new CodestartStructureException(
"Target file already exists: " + targetPath.toString());
}
}
default void createDirectories(Path targetPath) throws IOException {
Files.createDirectories(targetPath.getParent());
}
default void writeFile(final Path targetPath, final String content) throws IOException {
if (!SKIP_FILE_IDENTIFIER.equals(content)) {
Files.write(targetPath, content.getBytes(StandardCharsets.UTF_8));
}
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Clean the target directory or delete the conflicting file before regenerating
- Use a different target directory for the new project
- Choose a conflict strategy that permits overwrite (e.g. override) instead of one that fails on existing targets
Example fix
// before
handler.process(targetDir, "pom.xml", files, data); // pom.xml may exist
// after
Path p = targetDir.resolve("pom.xml");
if (Files.exists(p)) Files.delete(p);
handler.process(targetDir, "pom.xml", files, data); Defensive patterns
Strategy: validation
Validate before calling
if (Files.exists(targetDir.resolve(relativePath)))
throw new IllegalStateException("Exists: " + relativePath); Try / catch
try { generate.generateProject(targetDir); }
catch (CodestartStructureException e) {
if (e.getMessage().startsWith("Target file already exists:")) { /* clean or relocate */ }
else throw e;
} Prevention
- Generate into empty dirs only
- Clean stale output before regenerating
- Back up files before regeneration
When it happens
Trigger: A codestart file strategy that calls checkTargetDoesNotExist runs during generation while a file already exists at targetDirectory/relativePath — typically generating into a directory with pre-existing content.
Common situations: Generating into a non-empty or previously generated directory; renaming files in a codestart so new files collide with old ones; running generation twice without cleaning the output.
Related errors
- Failed to create output directory for generated sources: %s
- ${archiveRoot} does not point to the application output dire
- IOException (wrapped)
- Unable to validate the application root for remote-dev path:
- Path leaves the application root: <file>
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/7a47f5381b6eb9c5.
Report an issue: GitHub.