apache/maven · error · LifecycleExecutionException

Goal requires a project to execute but there is no POM in th

Error message

Goal requires a project to execute but there is no POM in this directory ({}). Please verify you invoked Maven from the correct directory.

What it means

MojoExecutor.execute() checks the mojo descriptor before running: if the plugin goal declares requiresProject=true (the default for most mojos) but the session has no project present, it throws LifecycleExecutionException wrapping a MissingProjectException naming the execution root directory. Unlike the starter-level check (DefaultLifecycleStarter), this one fires per-mojo, covering cases where the task parsed as a goal but the goal itself demands a project.

Source

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

        phaseRecorder.observeExecution(mojoExecution);
    }

    private void execute(MavenSession session, MojoExecution mojoExecution, DependencyContext dependencyContext)
            throws LifecycleExecutionException {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

        try {
            mavenPluginManager.checkPrerequisites(mojoDescriptor.getPluginDescriptor());
        } catch (PluginIncompatibleException e) {
            throw new LifecycleExecutionException(messageBuilderFactory, mojoExecution, session.getCurrentProject(), e);
        }

        if (mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent()) {
            Throwable cause = new MissingProjectException(
                    "Goal requires a project to execute" + " but there is no POM in this directory ("
                            + session.getExecutionRootDirectory() + ")."
                            + " Please verify you invoked Maven from the correct directory.");
            throw new LifecycleExecutionException(messageBuilderFactory, mojoExecution, null, cause);
        }

        if (mojoDescriptor.isOnlineRequired() && session.isOffline()) {
            if (MojoExecution.Source.CLI.equals(mojoExecution.getSource())) {
                Throwable cause = new IllegalStateException(
                        "Goal requires online mode for execution" + " but Maven is currently offline.");
                throw new LifecycleExecutionException(
                        messageBuilderFactory, mojoExecution, session.getCurrentProject(), cause);
            } else {
                eventCatapult.fire(ExecutionEvent.Type.MojoSkipped, session, mojoExecution);

                return;
            }
        }

        doExecute(session, mojoExecution, dependencyContext);
    }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Run the goal from a directory containing pom.xml, or pass -f /path/to/pom.xml
  2. Pick a projectless-capable variant/goal (goals explicitly marked requiresProject=false, like archetype:generate) if you truly have no POM
  3. For embedders, ensure MavenExecutionRequest is configured with a project (request.setPom/file present) before executing such mojos
  4. Guard scripts by testing [ -f pom.xml ] before invoking project-bound goals

Example fix

# before
cd /tmp && mvn dependency:resolve-goals   # goal requires a project

# after
cd /path/to/project && mvn compiler:compile
# or: mvn -f /path/to/project/pom.xml compiler:compile
Defensive patterns

Strategy: validation

Validate before calling

// check the mojo's requirement before executing
if (mojoDescriptor.isProjectRequired() && !session.getRequest().isProjectPresent()) {
    throw new MissingProjectException("Goal " + mojoDescriptor.getGoal() + " needs a project; supply pom.xml");
}

Try / catch

catch (LifecycleExecutionException e) {
    if (e.getCause() instanceof MissingProjectException) {
        // rerun from the project directory or with -f pointing at the POM
    }
}

Prevention

When it happens

Trigger: Invoking a requiresProject=true goal (most plugin goals, e.g. compiler:compile) with no pom.xml in the execution root — for example 'mvn compiler:compile' in an empty directory, or with -f pointing to a non-POM; also programmatic MojoExecution where the session request was built with isProjectPresent=false.

Common situations: Running one-off plugin goals outside a project; shell scripts starting in the wrong directory; embedders creating a project-less session but invoking standard mojos; IDE actions on a closed/deleted project.

Related errors


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