quarkusio/quarkus · error · MojoExecutionException

Unable to create the project, the directory ${projectRoot.ge

Error message

Unable to create the project, the directory ${projectRoot.getAbsolutePath()} already exists

What it means

The create goal computes the target project directory as outputDirectory/projectArtifactId. If that directory already exists on disk, scaffolding would overwrite or interleave with existing files, so the mojo refuses and throws this MojoExecutionException before writing anything.

Source

Thrown at devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java:300

            if (containsAtLeastOneGradleFile) {
                throw new MojoExecutionException("Adding subprojects to gradle projects is not implemented.");
            } else if (pom != null && pom.isFile()) {
                throw new MojoExecutionException(
                        "You are trying to create gradle project in a directory that contains only maven build files.");
            }
        }

        askTheUserForMissingValues();
        if (!DEFAULT_ARTIFACT_ID.equals(projectArtifactId) && !OK_ID.matcher(projectArtifactId).matches()) {
            throw new MojoExecutionException(String.format(BAD_IDENTIFIER, "artifactId", projectArtifactId));
        }
        if (!DEFAULT_GROUP_ID.equals(projectGroupId) && !OK_ID.matcher(projectGroupId).matches()) {
            throw new MojoExecutionException(String.format(BAD_IDENTIFIER, "groupId", projectGroupId));
        }

        projectRoot = new File(outputDirectory, projectArtifactId);
        if (projectRoot.exists()) {
            throw new MojoExecutionException("Unable to create the project, " +
                    "the directory " + projectRoot.getAbsolutePath() + " already exists");
        }

        boolean success;
        final Path projectDirPath = projectRoot.toPath();
        try {
            extensions = CreateProjectHelper.sanitizeExtensions(extensions);
            catalog = CreateProjectHelper.completeCatalog(catalog, extensions, mvn);
            sanitizeOptions();

            final List<ResourceLoader> codestartsResourceLoader = codestartLoadersBuilder(log)
                    .catalog(catalog)
                    .artifactResolver(mvn)
                    .build();
            QuarkusProject newProject = QuarkusProject.of(projectDirPath, catalog,
                    codestartsResourceLoader, log, buildToolEnum, new JavaVersion(javaVersion));
            final CreateProject createProject = new CreateProject(newProject)
                    .groupId(projectGroupId)

View on GitHub (pinned to e1c734241f)

Solutions

  1. Delete the existing directory (rm -rf outputDirectory/artifactId) if its contents are disposable
  2. Choose a different -DprojectArtifactId
  3. Use a different -DoutputDirectory
  4. Clean the CI workspace before rerunning the create step

Example fix

// before
mvn quarkus:create -DprojectArtifactId=demo   # target/demo already exists
// after
rm -rf target/demo
mvn quarkus:create -DprojectArtifactId=demo
Defensive patterns

Strategy: validation

Validate before calling

File target = new File(outputDirectory, artifactId);
if (target.exists()) {
    if (allowOverwrite) deleteRecursively(target); else throw new IllegalStateException("Target exists: " + target);
}

Try / catch

try {
    runCreateGoal();
} catch (MojoExecutionException e) {
    if (e.getMessage().contains("already exists")) {
        // remove the directory or pick a new artifactId/outputDirectory
    }
}

Prevention

When it happens

Trigger: Re-running `mvn quarkus:create` with the same -DprojectArtifactId in the same outputDirectory after a previous successful (or partially successful) run.

Common situations: CI re-runs without cleaning the workspace; retrying after a failed generation that left the directory behind; choosing an artifactId that collides with an existing folder name.

Related errors


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