quarkusio/quarkus · error · IllegalStateException

Cannot set both application root and app artifact

Error message

Cannot set both application root and app artifact

What it means

QuarkusBootstrap.Builder.setAppArtifact throws this IllegalStateException when an application root was already set. The two settings are mutually exclusive because setAppArtifact derives applicationRoot (and projectRoot for single-path artifacts) from the artifact's resolved paths.

Source

Thrown at independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/QuarkusBootstrap.java:484

        }

        public Builder setDisableClasspathCache(boolean disableClasspathCache) {
            this.disableClasspathCache = disableClasspathCache;
            return this;
        }

        public Builder addParentFirstArtifact(ArtifactKey appArtifactKey) {
            this.parentFirstArtifacts.add(appArtifactKey);
            return this;
        }

        /**
         * The app artifact. Note that if you want to use this as the basis of the application
         * you must also explicitly set the application root to this artifacts paths.
         */
        public Builder setAppArtifact(ResolvedDependency appArtifact) {
            if (applicationRoot != null) {
                throw new IllegalStateException("Cannot set both application root and app artifact");
            }
            this.appArtifact = appArtifact;
            this.applicationRoot = PathList.from(appArtifact.getResolvedPaths());
            if (appArtifact.getResolvedPaths().isSinglePath()) {
                this.projectRoot = appArtifact.getResolvedPaths().getSinglePath();
            }
            return this;
        }

        public Builder setManagingProject(ArtifactCoords managingProject) {
            this.managingProject = managingProject;
            return this;
        }

        /**
         * If the deployment should use an isolated (aka parent last) classloader.
         * <p>
         * For tests this is generally false, as we want to share the base class path so that the

View on GitHub (pinned to e1c734241f)

Solutions

  1. Drop the setApplicationRoot call and rely on setAppArtifact to derive the root from the artifact's resolved paths.
  2. Or keep setApplicationRoot and do not call setAppArtifact.
  3. Restructure the builder usage so the source of truth (artifact vs. directory) is decided once before building.

Example fix

// before
QuarkusBootstrap.builder().setApplicationRoot(paths).setAppArtifact(dep)
// after
QuarkusBootstrap.builder().setAppArtifact(dep) // root taken from dep.getResolvedPaths()
Defensive patterns

Strategy: validation

Validate before calling

QuarkusBootstrap.Builder b = QuarkusBootstrap.builder();
if (appArtifact == null) b.setApplicationRoot(paths); else b.setAppArtifact(appArtifact);

Prevention

When it happens

Trigger: Calling QuarkusBootstrap.builder().setApplicationRoot(paths).setAppArtifact(dep) — i.e. invoking setAppArtifact after setApplicationRoot on the same Builder.

Common situations: Test harnesses or launchers that pre-configure an application root from the project directory and then also attach a resolved dependency as the app artifact (e.g. when adapting between local-run and artifact-run modes).

Related errors


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