quarkusio/quarkus · error · java.lang.RuntimeException

mainComponent is null

Error message

mainComponent is null

What it means

During SBOM generation, CoreSbomContributionConfig.resolveMainComponent() computes the SBOM's 'main component' from the main artifact or, failing that, the first collected component. If neither exists, it throws 'mainComponent is null' — the application has no identifiable main artifact/component to anchor the SBOM.

Source

Thrown at independent-projects/bootstrap/app-model/src/main/java/io/quarkus/sbom/CoreSbomContributionConfig.java:377

        return bomRef + "-" + counter.incrementAndGet();
    }

    private ComponentHolder resolveMainComponent(
            Map<ArtifactKey, ComponentHolder> compArtifacts,
            Map<Path, ComponentHolder> compPaths,
            List<ComponentHolder> compList) {
        ComponentHolder main;
        if (mainPurl != null) {
            main = addComponentHolder(ComponentDescriptor.builder()
                    .setPurl(mainPurl)
                    .setPath(runnerPath), null, compArtifacts, compPaths, compList);
        } else if (mainArtifact != null) {
            main = addComponentHolder(toMavenDescriptor(mainArtifact), mainArtifact,
                    compArtifacts, compPaths, compList);
        } else if (!compList.isEmpty()) {
            main = compList.get(0);
        } else {
            throw new RuntimeException("mainComponent is null");
        }
        if (runnerPath != null && mainPurl == null) {
            overridePath(main, runnerPath, compPaths);
        }
        if (mainDependencies != null) {
            main.explicitDependencies = mainDependencies;
        }
        return main;
    }

    private static void overridePath(ComponentHolder holder, Path newPath,
            Map<Path, ComponentHolder> compPaths) {
        if (newPath.equals(holder.path)) {
            return;
        }
        if (holder.path != null) {
            compPaths.remove(holder.path);
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Build the application normally (a main artifact should always exist); run mvn package/quarkus:build without custom artifact filtering
  2. Disable SBOM generation if not needed (remove quarkus.sbom.enabled=true)
  3. Ensure dependency resolution isn't skipped (don't combine SBOM with -Dmaven.main.skip or similar)
  4. File a bug with the build log if a standard build triggers it

Example fix

// before
mvn quarkus:build -Dquarkus.sbom.enabled=true -Dmdep.skip=true
// after
mvn quarkus:build -Dquarkus.sbom.enabled=true   # allow full dependency resolution
Defensive patterns

Strategy: validation

Validate before calling

// before enabling SBOM, ensure a main artifact exists
if (project.getArtifact().getFile() == null) { throw new IllegalStateException("Main artifact not built; cannot generate SBOM"); }

Try / catch

try { generateSbom(); } catch (RuntimeException e) { if ("mainComponent is null".equals(e.getMessage())) { log.error("No main artifact for SBOM; check build config"); } else { throw e; } }

Prevention

When it happens

Trigger: Running with SBOM generation enabled (quarkus.sbom.enabled / -Dquarkus.sbom.enabled=true) when no main artifact was recorded and the component list is empty — e.g. building a bare/thin artifact without dependencies or the main artifact not being registered.

Common situations: Building unusual packaging types or empty applications; SBOM enabled on a build that skipped dependency resolution; internal build pipelines filtering out the runner artifact.

Related errors


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