quarkusio/quarkus · error · IllegalArgumentException
Target directory already exists: ${path}
Error message
Target directory already exists: ${path} What it means
checkProjectRootPath computes outputPath/name and refuses to proceed if that directory already exists, to avoid overwriting an existing project. It throws an IllegalArgumentException containing the absolute target directory path.
Source
Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProjectHelper.java:150
throw new IllegalArgumentException(name + " is not a valid class name");
}
return name;
}
public static String checkPackageName(String name) {
if (!SourceVersion.isName(name)) { // checks for valid identifiers & use of keywords
throw new IllegalArgumentException(name + " is not a valid package name");
}
return name;
}
public static Path checkProjectRootPath(Path outputPath, String name) {
requireNonNull(name, "Must specify project name");
requireNonNull(outputPath, "Must specify output path");
Path projectRootPath = outputPath.resolve(name);
if (projectRootPath.toFile().exists()) {
throw new IllegalArgumentException(
"Target directory already exists: " + projectRootPath.toAbsolutePath().toString());
}
return projectRootPath;
}
public static Path createOutputDirectory(String targetDirectory) {
Path origin = new File(System.getProperty("user.dir")).toPath();
Path outputPath = (targetDirectory == null ? origin : origin.resolve(targetDirectory));
try {
Files.createDirectories(outputPath);
} catch (IOException e) {
throw new IllegalArgumentException("Could not create directory " + targetDirectory, e);
}
return outputPath;
}
public static Set<String> sanitizeExtensions(Set<String> extensions) {
if (extensions == null) {View on GitHub (pinned to e1c734241f)
Solutions
- Choose a different project name or output directory
- Delete or move the existing target directory before re-running
- Point outputPath at an empty location
- If overwrite is truly intended, remove the directory explicitly: rm -rf <dir>
Example fix
// before
createProject.outputDirectory(Path.of(".")); createProject.name("my-app"); // ./my-app exists
// after
rm -rf ./my-app // or use name("my-app-v2") Defensive patterns
Strategy: validation
Validate before calling
Path root = outputPath.resolve(name);
if (root.toFile().exists()) { throw new IllegalArgumentException("choose another name/output or remove " + root.toAbsolutePath()); } Try / catch
try { helper.checkProjectRootPath(outputPath, name); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Target directory already exists")) { useAlternateDirOrAbort(); } } Prevention
- Check target directory existence before invoking project creation
- Use unique output directories per generation run in CI
- Clean up failed generation outputs before re-running
When it happens
Trigger: Calling CreateProject (or checkProjectRootPath directly) where outputPath.resolve(name) already exists on disk — e.g. re-running generation into the same output directory with the same project name.
Common situations: Re-running a failed/interrupted generation after some files were created; scaffolding into a directory that already holds another project; running the same script twice without cleaning output.
Related errors
- The version 2 CLI can not be used with Quarkus 1.x projects.
- Could not create directory ${outputDirectory}
- Failed to create the project directory: + targetDirectory
- Project path needs to point to a directory: + targetDirector
- You can't create a project when the directory is not empty:
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/b0dbd6290307d0b8.
Report an issue: GitHub.