apache/maven · error · LifecycleExecutionException

Goal requires online mode for execution but Maven is current

Error message

Goal requires online mode for execution but Maven is currently offline.

What it means

Before executing a mojo, MojoExecutor checks the descriptor's requiresOnline flag against the session: if the goal needs network access but Maven runs with -o/--offline, the behavior splits by source. For a CLI-invoked goal (MojoExecution.Source.CLI) Maven throws LifecycleExecutionException wrapping this IllegalStateException; for lifecycle-bound executions it fires a MojoSkipped event instead and silently skips.

Source

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

        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);
    }

    protected static class NoLock implements NoExceptionCloseable {
        public NoLock() {}

        @Override
        public void close() {}
    }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Drop -o/--offline for that invocation (e.g. mvn versions:display-plugin-updates) since the goal genuinely needs remotes
  2. Pre-populate the local repository first (run once online, or copy the repo) and keep offline for the rest of the build
  3. If the goal is lifecycle-bound, be aware it will be silently skipped offline — check build logs for MojoSkipped instead of failures
  4. Pin plugin/goal choices in offline pipelines to goals that do not require online

Example fix

# before
mvn -o versions:display-dependency-updates   # goal requires online

# after
mvn versions:display-dependency-updates
# or stay offline but accept the skip for lifecycle-bound executions
Defensive patterns

Strategy: validation

Validate before calling

// before invoking a goal in an offline-capable pipeline
if (mojoDescriptor.isOnlineRequired() && session.isOffline()) {
    throw new IllegalStateException("Goal " + goal + " requires online mode; disable -o or pre-seed the local repo");
}

Try / catch

catch (LifecycleExecutionException e) {
    if (e.getCause() instanceof IllegalStateException ise
            && ise.getMessage().contains("offline")) {
        // rerun online: remove -o from the invocation
    }
}

Prevention

When it happens

Trigger: Running a requiresOnline=true goal (e.g. goals that download remote metadata or hit remote services) with mvn -o or --offline-mode configured; a CLI goal like versions:display-dependency-updates in offline mode fails here, while the same goal bound to a lifecycle phase would just be skipped.

Common situations: Air-gapped CI builds forcing -o for reproducibility and then calling a goal that must reach remotes; developers enabling offline to speed builds and forgetting a specific goal needs the network; proxies mirroring everything but leaving offline on.

Related errors


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