Class ApiRunner

java.lang.Object
org.apache.maven.impl.standalone.ApiRunner

public class ApiRunner extends Object
Provides functionality for running Maven API in a standalone mode.

This class serves as the main entry point for executing Maven operations outside of the standard Maven build environment. It provides methods for creating and managing Maven sessions in a simplified context, suitable for tools, IDE integrations, and specialized execution scenarios.

The standalone session reads and applies the user's settings.xml including:

  • Local repository location
  • Server authentication (username, password, private key)
  • Proxy configuration
  • Mirror configuration
  • Repository definitions from active profiles
  • Offline mode

It also loads maven-system.properties from the Maven configuration directory (${maven.home}/conf or as configured via maven.installation.conf/maven.conf) and from the user's Maven home (~/.m2/), merging both into the session's system properties. User properties are loaded from ~/.m2/maven-user.properties and exposed via ProtoSession.getUserProperties().

Example usage:

Session session = ApiRunner.createSession();
// Use session for Maven operations

The standalone mode provides a subset of Maven's functionality, with some features being unavailable or simplified. Operations not supported in standalone mode will throw UnsupportedInStandaloneModeException.

Since:
4.0.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Controls how the standalone session handles settings encryption/decryption.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.maven.api.Session
    Creates a new Maven session with default configuration.
    static org.apache.maven.api.Session
    createSession(Consumer<org.apache.maven.di.Injector> injectorConsumer)
    Creates a new Maven session with custom injector configuration.
    static org.apache.maven.api.Session
    createSession(Consumer<org.apache.maven.di.Injector> injectorConsumer, Path localRepo)
    Creates a new Maven session with custom injector configuration and local repository path.
    static org.apache.maven.api.Session
    createSession(Consumer<org.apache.maven.di.Injector> injectorConsumer, Path localRepo, ApiRunner.SecurityMode securityMode)
    Creates a new Maven session with custom injector configuration, local repository path, and security mode.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ApiRunner

      public ApiRunner()
  • Method Details

    • createSession

      public static org.apache.maven.api.Session createSession()
      Creates a new Maven session with default configuration.
      Returns:
      a new Session instance
    • createSession

      public static org.apache.maven.api.Session createSession(Consumer<org.apache.maven.di.Injector> injectorConsumer)
      Creates a new Maven session with custom injector configuration.
      Parameters:
      injectorConsumer - consumer function to customize the injector
      Returns:
      a new Session instance
    • createSession

      public static org.apache.maven.api.Session createSession(Consumer<org.apache.maven.di.Injector> injectorConsumer, Path localRepo)
      Creates a new Maven session with custom injector configuration and local repository path.
      Parameters:
      injectorConsumer - consumer function to customize the injector
      localRepo - path to the local repository
      Returns:
      a new Session instance
    • createSession

      public static org.apache.maven.api.Session createSession(Consumer<org.apache.maven.di.Injector> injectorConsumer, Path localRepo, ApiRunner.SecurityMode securityMode)
      Creates a new Maven session with custom injector configuration, local repository path, and security mode.
      Parameters:
      injectorConsumer - consumer function to customize the injector
      localRepo - path to the local repository
      securityMode - controls how encrypted passwords in settings are handled
      Returns:
      a new Session instance