quarkusio/quarkus · error · IOException

Project path needs to point to a directory: + targetDirector

Error message

Project path needs to point to a directory: + targetDirectory

What it means

CodestartProcessor.checkTargetDir() throws IOException('Project path needs to point to a directory: <targetDirectory>') when the given target path exists but is a regular file (or other non-directory), so a project cannot be generated into it.

Source

Thrown at independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/CodestartProcessor.java:71

        codestart.use(l -> {
            final Map<String, Object> finalData = CodestartData.buildCodestartData(codestart, languageName, data);
            log.debug("codestart data: %s", finalData);
            Stream.of(BASE_LANGUAGE, languageName)
                    .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());

View on GitHub (pinned to e1c734241f)

Solutions

  1. Point the generation target at a new (or existing empty) directory path instead of a file.
  2. Remove or rename the file currently occupying the intended directory path.
  3. Validate the target path is a directory before invoking project generation.

Example fix

// before
Path target = Path.of("/home/user/notes.txt");
generateProject(target, ...); // IOException
// after
Path target = Path.of("/home/user/projects/my-app");
generateProject(target, ...);
Defensive patterns

Strategy: validation

Validate before calling

Path target = Path.of(dest);
if (Files.exists(target) && !Files.isDirectory(target)) {
    throw new IllegalArgumentException("Target exists and is not a directory: " + target);
}

Type guard

boolean isUsableTargetDir(Path p) {
    return p != null && (!java.nio.file.Files.exists(p) || java.nio.file.Files.isDirectory(p));
}

Try / catch

try {
    processor.generateProject(...);
} catch (IOException e) {
    if (e.getMessage().startsWith("Project path needs to point to a directory")) {
        logger.error("Target is a file, choose a directory path: " + targetDir);
    }
    throw e;
}

Prevention

When it happens

Trigger: Passing an existing file path as the target directory for project generation — checkTargetDir finds Files.exists() true but Files.isDirectory() false.

Common situations: Typoed output path pointing at an existing file; reusing a path variable that holds a file; shell completion or scripts resolving to a file.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/ee8d3207b6764fcb. Report an issue: GitHub.