apache/maven · error · MavenExecutionException

The project exclusion%s in --projects/-pl resulted in an emp

Error message

The project exclusion%s in --projects/-pl resulted in an empty reactor, please correct %s.

What it means

MavenExecutionException thrown by the graph builder when project exclusions (--projects/-pl with '!' selectors) remove every project from the reactor, leaving nothing to build. It is computed after result.removeAll(excludedProjects) over the full module list; the message pluralizes ('exclusion(s)', 'correct it/them') based on how many selectors were excluded.

Source

Thrown at impl/maven-core/src/main/java/org/apache/maven/graph/DefaultGraphBuilder.java:256

        Set<String> optionalSelectors = projectActivation.getOptionalInactiveProjectSelectors();
        if (!requiredSelectors.isEmpty() || !optionalSelectors.isEmpty()) {
            Set<MavenProject> excludedProjects = new HashSet<>(requiredSelectors.size() + optionalSelectors.size());
            List<MavenProject> allProjects = graph.getAllProjects();
            excludedProjects.addAll(
                    projectSelector.getRequiredProjectsBySelectors(request, allProjects, requiredSelectors));
            excludedProjects.addAll(
                    projectSelector.getOptionalProjectsBySelectors(request, allProjects, optionalSelectors));

            result = new ArrayList<>(projects);
            result.removeAll(excludedProjects);

            if (result.isEmpty()) {
                boolean isPlural = excludedProjects.size() > 1;
                String message = String.format(
                        "The project exclusion%s in --projects/-pl resulted in an "
                                + "empty reactor, please correct %s.",
                        isPlural ? "s" : "", isPlural ? "them" : "it");
                throw new MavenExecutionException(message, request.getPom());
            }
        }

        return result;
    }

    private List<MavenProject> includeAlsoMakeTransitively(
            List<MavenProject> projects, MavenExecutionRequest request, ProjectDependencyGraph graph)
            throws MavenExecutionException {
        List<MavenProject> result = projects;

        String makeBehavior = request.getMakeBehavior();
        boolean makeBoth = MavenExecutionRequest.REACTOR_MAKE_BOTH.equals(makeBehavior);

        boolean makeUpstream = makeBoth || MavenExecutionRequest.REACTOR_MAKE_UPSTREAM.equals(makeBehavior);
        boolean makeDownstream = makeBoth || MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM.equals(makeBehavior);

        if ((makeBehavior != null && !makeBehavior.isEmpty()) && !makeUpstream && !makeDownstream) {

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Re-run keeping at least one module: mvn -pl 'app,!app-it' install
  2. Quote the selectors so the shell does not interpret '!': mvn -pl "!module-to-skip"
  3. Verify what the selectors match against the reactor module list (mvn help:evaluate -Dexpression=project.modules or the build summary) before excluding

Example fix

# before: exclusion leaves an empty reactor
mvn -pl '!app' install

# after: keep one module, exclude another
mvn -pl 'app,!app-it' install
Defensive patterns

Strategy: validation

Validate before calling

// With the reactor module list known, simulate the selection before invoking Maven
List<String> modules = List.of("app", "app-it", "docs"); // e.g. parsed from the root pom
Set<String> selected = new HashSet<>(modules);
selected.removeAll(Set.of(exclusions)); // exclusions from -pl '!x'
if (selected.isEmpty()) {
    throw new IllegalArgumentException("-pl exclusions remove every module; keep at least one");
}

Prevention

When it happens

Trigger: mvn -pl '!module' (or mixed selection like -pl 'app,!app') where the exclusion set covers all reactor projects — e.g. a single-module reactor with -pl '!app', or excluding the root plus every module, or quoting mistakes that turn the entire selection into exclusions.

Common situations: Shell quoting errors where '!' expands or the whole argument becomes an exclusion; excluding the only module in a small reactor; combining -pl '!x' with -amd expecting projects that are not in the graph.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/6121aad0cf46ace2. Report an issue: GitHub.