quarkusio/quarkus · error · IllegalStateException

There is no rootProject defined in this GradleBuildFile

Error message

There is no rootProject defined in this GradleBuildFile

What it means

AbstractGradleBuildFile.readRootProjectFile(fileName) reads files (like gradle.properties or settings via settings()/properties()) relative to the root project directory. If rootProjectPath was never set (multi-module layouts where no root project was identified), it throws IllegalStateException with this message instead of failing with an IO error.

Source

Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/AbstractGradleBuildFile.java:161

        });
    }

    @Override
    protected void refreshData() {
        this.modelReference.set(null);
    }

    private boolean hasRootProjectFile(final String fileName) {
        if (rootProjectPath == null) {
            return false;
        }
        final Path filePath = rootProjectPath.resolve(fileName);
        return Files.exists(filePath);
    }

    private byte[] readRootProjectFile(final String fileName) throws IOException {
        if (rootProjectPath == null) {
            throw new IllegalStateException("There is no rootProject defined in this GradleBuildFile");
        }
        final Path filePath = rootProjectPath.resolve(fileName);
        return Files.readAllBytes(filePath);
    }

    private Model readModel() throws IOException {
        String settingsContent = "";
        String buildContent = "";
        Properties propertiesContent = new Properties();
        String rootSettingsContent = null;
        Properties rootPropertiesContent = null;
        if (hasProjectFile(getSettingsGradlePath())) {
            final byte[] settings = readProjectFile(getSettingsGradlePath());
            settingsContent = new String(settings, StandardCharsets.UTF_8);
        }
        if (hasRootProjectFile(getSettingsGradlePath())) {
            final byte[] settings = readRootProjectFile(getSettingsGradlePath());
            rootSettingsContent = new String(settings, StandardCharsets.UTF_8);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the project has a settings.gradle at its root and that the build file is constructed with the root project path (or an ancestor directory containing it).
  2. Run the command from, or pass as projectDir, the actual Gradle root project directory rather than a submodule.
  3. If you invoke this API on a submodule, point the tool at the root: gradle/quarkus CLI commands generally accept the root directory.

Example fix

// before
GradleBuildFile f = new GradleBuildFile(Path.of("app/submodule")); // no settings.gradle above
// after
GradleBuildFile f = new GradleBuildFile(Path.of("app")); // root project with settings.gradle
Defensive patterns

Strategy: validation

Validate before calling

// verify a root project (settings.gradle) exists at or above the directory
Path p = projectDir;
while (p != null && !Files.exists(p.resolve("settings.gradle")) && !Files.exists(p.resolve("settings.gradle.kts"))) {
    p = p.getParent();
}
if (p == null) throw new IllegalStateException("no Gradle root project found for " + projectDir);

Try / catch

try {
    Map<String, String> props = gradleBuildFile.properties();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("no rootProject defined")) {
        // reconstruct the build file against the true root project directory
    }
}

Prevention

When it happens

Trigger: Calling settings() or properties() on an AbstractGradleBuildFile instance whose rootProjectPath is null — i.e. the build file was created without a resolvable root project directory (no settings.gradle found above the build file).

Common situations: Using the devtools Gradle project API in a nested/submodule directory where no settings.gradle exists in any parent; programmatically constructing GradleBuildFile without establishing the root project; renaming/moving settings.gradle so root detection fails.

Related errors


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