quarkusio/quarkus · error · MojoExecutionException

You are trying to create gradle Project in a directory that

Error message

You are trying to create gradle Project in a directory that contains only maven build files.

What it means

The inverse of the Maven-vs-Gradle check: when the create goal is asked for a Gradle project (buildTool=gradle or gradle-kotlin-dsl) but the target directory contains a pom.xml and no Gradle files, the mojo throws this MojoExecutionException. It prevents nesting a Gradle build inside a Maven project directory.

Source

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

                try {
                    parentPomModel = MojoUtils.readPom(pom);
                    if (!"pom".equals(parentPomModel.getPackaging())) {
                        throw new MojoExecutionException(
                                "The parent project must have a packaging type of POM. Current packaging: "
                                        + parentPomModel.getPackaging());
                    }
                } catch (IOException e) {
                    throw new MojoExecutionException("Could not access parent pom.", e);
                }
            } else if (containsAtLeastOneGradleFile) {
                throw new MojoExecutionException(
                        "You are trying to create a Maven project in a directory that contains only Gradle build files.");
            }
        } else if (BuildTool.GRADLE.equals(buildToolEnum) || BuildTool.GRADLE_KOTLIN_DSL.equals(buildToolEnum)) {
            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");
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Create the Gradle project in an empty directory instead
  2. Drop the -DbuildTool=gradle flag (or set it to maven) to match the existing Maven directory
  3. Move out of the Maven project directory before generating a Gradle project

Example fix

// before
mvn quarkus:create -DbuildTool=gradle   # inside dir with pom.xml
// after
cd /path/to/empty-dir && mvn quarkus:create -DbuildTool=gradle
Defensive patterns

Strategy: validation

Validate before calling

boolean hasPom = new File(dir, "pom.xml").isFile();
if (buildTool.startsWith("gradle") && hasPom) throw new IllegalStateException("Maven-only directory; use an empty dir for Gradle");

Try / catch

try {
    runCreateGoal();
} catch (MojoExecutionException e) {
    if (e.getMessage().contains("directory that contains only maven build files")) {
        // cd to an empty directory or drop -DbuildTool=gradle
    }
}

Prevention

When it happens

Trigger: Running `mvn quarkus:create -DbuildTool=gradle` in a directory that already has a pom.xml (project != null, pom.isFile()).

Common situations: Choosing Gradle in a prompt or script while sitting inside a Maven multi-module checkout; accidentally mixing tool flags in CI.

Related errors


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