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
- Restore the standard Maven/Gradle directory layout so the sources root can be derived from the output directory
- Use an absolute path for the configured Dockerfile so resolution does not depend on the sources root
- Verify the build output directory (target/ or build/) is in its default location relative to the project root
- 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
- Keep the standard Maven/Gradle output layout (target/classes, build/classes)
- Prefer absolute Dockerfile paths in heavily customized builds
- Run image builds from the project root
- Avoid relocating target/ via non-standard build configurations
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
- Unable to find root of Dockerfile files. Consider adding 'sr
- Specified Dockerfile path %s does not exist
- Could not find builder image '${effectiveBuilderImage}' loca
- The 'buildx' properties are specific to 'executable-name=doc
- Unable to find Dockerfile %s in %s
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/3b47ee2700563fd3.
Report an issue: GitHub.