quarkusio/quarkus · error · IOException
You can't create a project when the directory is not empty:
Error message
You can't create a project when the directory is not empty: + targetDirectory
What it means
CodestartProcessor.checkTargetDir validates the target directory before generating project files. This error means the given path exists, is a directory, but already contains files, so generating a project would risk overwriting existing content. The library refuses to proceed to protect the existing directory contents.
Source
Thrown at independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartProcessor.java:75
.filter(l::dirExists)
.forEach(languageDir -> processLanguageDir(projectResource, l, languageDir, finalData));
});
}
public void checkTargetDir() throws IOException {
if (!Files.exists(targetDirectory)) {
boolean mkdirStatus = targetDirectory.toFile().mkdirs();
if (!mkdirStatus) {
throw new IOException("Failed to create the project directory: " + targetDirectory);
}
return;
}
if (!Files.isDirectory(targetDirectory)) {
throw new IOException("Project path needs to point to a directory: " + targetDirectory);
}
final String[] files = targetDirectory.toFile().list();
if (files != null && files.length > 0) {
throw new IOException("You can't create a project when the directory is not empty: " + targetDirectory);
}
}
public void writeFiles() throws IOException {
for (Map.Entry<String, List<TargetFile>> e : files.entrySet()) {
final String relativePath = e.getKey();
final CodestartFileStrategyHandler strategy = getStrategy(relativePath).orElse(getSelectedDefaultStrategy());
log.debug("processing file '%s' with strategy %s", relativePath, strategy.name());
strategy.process(targetDirectory, relativePath, e.getValue(), data);
}
}
public static List<CodestartFileStrategy> buildStrategies(Map<String, String> spec) {
final List<CodestartFileStrategy> codestartFileStrategyHandlers = new ArrayList<>(spec.size());
for (Map.Entry<String, String> entry : spec.entrySet()) {
final CodestartFileStrategyHandler handler = CodestartFileStrategyHandler.BY_NAME.get(entry.getValue());
if (handler == null) {View on GitHub (pinned to e1c734241f)
Solutions
- Empty the target directory (remove or move its contents) and re-run generation
- Choose a different, empty or non-existent target directory
- Pre-check the directory yourself with Files.list and abort or warn the user before calling generate
Example fix
// before
generate.generateProject(targetDir);
// after
try (Stream<Path> s = Files.list(targetDir)) {
if (s.findAny().isPresent()) {
throw new IllegalStateException("Target dir must be empty: " + targetDir);
}
}
generate.generateProject(targetDir); Defensive patterns
Strategy: validation
Validate before calling
try (Stream<Path> s = Files.list(targetDir)) {
if (s.findAny().isPresent()) throw new IllegalStateException("Target dir not empty: " + targetDir);
} else if (!Files.isDirectory(targetDir)) {
throw new IllegalStateException("Target path is not a directory: " + targetDir);
} Try / catch
try {
generate.generateProject(targetDir);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().startsWith("You can't create a project when the directory is not empty")) {
// clean up or choose a different directory, then retry
} else throw e;
} Prevention
- Always generate into fresh paths
- Check directory emptiness before calling generateProject
- Confirm with users in tooling before writing into existing dirs
When it happens
Trigger: Calling generateProject (via CodestartProjectGeneration/CodestartLoader APIs or quarkus CLI create) into an existing, non-empty directory.
Common situations: Running project generation twice into the same folder; generating into a folder that already contains a git repo, README, or IDE files; accidentally pointing targetDir at the parent project directory.
Related errors
- Could not create directory ${outputDirectory}
- Failed to create the project directory: + targetDirectory
- Project path needs to point to a directory: + targetDirector
- Could not create directory ${dir}
- Failed to create output directory for generated sources: %s
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/e07625879cd7e9aa.
Report an issue: GitHub.