quarkusio/quarkus · error · IllegalStateException

Unable to determine project root

Error message

Unable to determine project root

What it means

When a custom Dockerfile path is configured (quarkus.container-image.docker.dockerfile-jvm-path or -native-path), ProvidedDockerfile.get() first resolves the project's main sources root from the build output directory. If that root cannot be determined, it throws this IllegalStateException because relative Dockerfile paths cannot be resolved.

Source

Thrown at extensions/container-image/container-image-docker-common/deployment/src/main/java/io/quarkus/container/image/docker/common/deployment/CommonProcessor.java:425

            if (mainSourcesRoot == null) {
                return null;
            }

            var dockerfilesRoot = mainSourcesRoot.getKey().resolve(DOCKER_DIRECTORY_NAME);
            if (!dockerfilesRoot.toFile().exists()) {
                return null;
            }

            return new AbstractMap.SimpleEntry<>(dockerfilesRoot, mainSourcesRoot.getValue());
        }
    }

    protected record ProvidedDockerfile(Path dockerfilePath, Path dockerExecutionPath) implements DockerfilePaths {
        protected static DockerfilePaths get(Path dockerfilePath, Path outputDirectory) {
            var mainSourcesRoot = findMainSourcesRoot(outputDirectory);

            if (mainSourcesRoot == null) {
                throw new IllegalStateException("Unable to determine project root");
            }

            var executionPath = mainSourcesRoot.getValue();
            var effectiveDockerfilePath = dockerfilePath.isAbsolute() ? dockerfilePath : executionPath.resolve(dockerfilePath);

            if (!effectiveDockerfilePath.toFile().exists()) {
                throw new IllegalArgumentException(
                        "Specified Dockerfile path %s does not exist".formatted(effectiveDockerfilePath.toAbsolutePath()));
            }

            return new ProvidedDockerfile(effectiveDockerfilePath, executionPath);
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Restore the standard Maven/Gradle directory layout so the sources root can be derived from the output directory
  2. Use an absolute path for the configured Dockerfile so resolution does not depend on the sources root
  3. Verify the build output directory (target/ or build/) is in its default location relative to the project root
  4. Run the build from the project root rather than from an external directory

Example fix

# before (relative path, odd layout)
quarkus.container-image.docker.dockerfile-jvm-path=docker/Dockerfile.jvm
# after (absolute path)
quarkus.container-image.docker.dockerfile-jvm-path=/opt/ci/docker/Dockerfile.jvm
Defensive patterns

Strategy: fallback

Validate before calling

Path output = Path.of("target/classes");
Path projectRoot = output.getParent() == null ? null : output.getParent().getParent();
if (projectRoot == null || !Files.isDirectory(projectRoot.resolve("src/main"))) {
    System.err.println("WARN: project root not derivable; use an absolute dockerfile path");
}

Type guard

boolean sourcesRootDerivable(Path outputDirectory) {
    Path p = outputDirectory;
    for (int i = 0; i < 3 && p != null; i++) {
        if (Files.isDirectory(p.resolve("src/main"))) return true;
        p = p.getParent();
    }
    return false;
}

Try / catch

try {
    buildImage();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Unable to determine project root")) {
        throw new IllegalStateException("Use an absolute quarkus.container-image.docker.dockerfile-*-path or standard layout", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Building a container image with a custom dockerfile-jvm-path/dockerfile-native-path set while the output directory layout does not allow deriving the sources root (e.g. unusual project structure, relocated target/ directory, non-standard build setups).

Common situations: Highly customized Maven/Gradle builds that move the classes output far from the project root; invoking the image build from a stripped/copied project tree; monorepo setups where outputDirectory sits in an unexpected place.

Related errors


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