apache/maven · error · NoGoalSpecifiedException

No goals have been specified for this build. You must specif

Error message

No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: {}.

What it means

After calculating task segments and project builds, if the resulting ProjectBuildList is empty, DefaultLifecycleStarter throws NoGoalSpecifiedException: Maven was invoked with nothing to do — no lifecycle phase and no plugin goal survived into the task segments (which also covers bare 'mvn' with no arguments).

Source

Thrown at impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleStarter.java:95

    public void execute(MavenSession session) {
        eventCatapult.fire(ExecutionEvent.Type.SessionStarted, session, null);

        ReactorContext reactorContext = null;
        ProjectBuildList projectBuilds = null;
        MavenExecutionResult result = session.getResult();

        try {
            if (buildExecutionRequiresProject(session) && projectIsNotPresent(session)) {
                throw new MissingProjectException("The goal you specified requires a project to execute"
                        + " but there is no POM in this directory (" + session.getExecutionRootDirectory() + ")."
                        + " Please verify you invoked Maven from the correct directory.");
            }

            List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments(session);
            projectBuilds = buildListCalculator.calculateProjectBuilds(session, taskSegments);

            if (projectBuilds.isEmpty()) {
                throw new NoGoalSpecifiedException("No goals have been specified for this build."
                        + " You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or"
                        + " <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>."
                        + " Available lifecycle phases are: " + defaultLifeCycles.getLifecyclePhaseList() + ".");
            }

            if (logger.isDebugEnabled()) {
                lifecycleDebugLogger.debugReactorPlan(projectBuilds);
            }

            ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
            ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus(session.getProjectDependencyGraph());
            reactorContext = new ReactorContext(result, oldContextClassLoader, reactorBuildStatus);

            String builderId = session.getRequest().getBuilderId();
            Builder builder = builders.get(builderId);
            if (builder == null) {
                throw new BuilderNotFoundException(
                        String.format("The builder requested using id = %s cannot be" + " found", builderId));

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Add an explicit lifecycle phase or goal: mvn install / mvn org.acme:plugin:1.0:goal
  2. If goals come from a variable, guard the script: ${GOALS:?no goals set} or set a default GOALS=${GOALS:-package}
  3. Review the message's list of valid phases when unsure of naming

Example fix

# before
mvn ${GOALS}   # GOALS unset -> NoGoalSpecifiedException

# after
GOALS=${GOALS:-package}
mvn ${GOALS}
Defensive patterns

Strategy: validation

Validate before calling

// never invoke Maven with an empty goal list
if (goals == null || goals.isBlank()) throw new IllegalArgumentException("No goals specified");

Try / catch

catch (NoGoalSpecifiedException e) {
    // default the build to a sane phase (e.g. 'package') and retry
}

Prevention

When it happens

Trigger: Running 'mvn' with no goals; passing only flags (-T 1C, -DskipTests, --file pom.xml) without a phase/goal; all requested tasks filtered out by task-segment calculation; -Dgoals style configurations where the property supplying goals is empty.

Common situations: CI scripts building the goal list from an empty variable: mvn ${GOALS} with GOALS unset; shell quoting bugs that drop the goal argument; users expecting a default phase like 'install' to run implicitly.

Related errors


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