or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-plugin-development.mdexception-handling.mdindex.mdlogging-system.mdplugin-descriptors.md
tile.json

tessl/maven-org-apache-maven--maven-plugin-api

The API for plugins - Mojos - development

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.apache.maven/maven-plugin-api@3.9.x

To install, run

npx @tessl/cli install tessl/maven-org-apache-maven--maven-plugin-api@3.9.0

index.mddocs/

Maven Plugin API

The API for plugins - Mojos - development. This library provides the core interfaces, classes, and abstractions needed to develop Maven plugins that extend Maven's functionality during the build lifecycle.

Package Information

  • Package Name: org.apache.maven:maven-plugin-api
  • Package Type: Maven
  • Language: Java
  • Installation: Add to your pom.xml dependencies:
<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-plugin-api</artifactId>
    <version>3.9.11</version>
</dependency>

Core Imports

import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.monitor.logging.DefaultLog;

Basic Usage

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * Example Maven plugin that demonstrates basic usage
 * @goal hello
 */
public class HelloMojo extends AbstractMojo {
    
    /**
     * @parameter property="greeting" default-value="Hello World!"
     */
    private String greeting;
    
    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        Log log = getLog();
        log.info(greeting);
        
        try {
            // Plugin logic here
            log.debug("Executing hello goal");
        } catch (Exception e) {
            throw new MojoExecutionException("Unexpected error", e);
        }
    }
}

Architecture

The Maven Plugin API is built around several key components:

  • Mojo Interface: The contract that all Maven plugins must implement to interact with Maven
  • AbstractMojo: Base class providing infrastructure like logging and context management
  • Exception Hierarchy: Distinguishes between unexpected errors (MojoExecutionException) and expected failures (MojoFailureException)
  • Logging System: Standardized logging interface that integrates with Maven's output system
  • Descriptor System: Metadata classes that describe plugins, mojos, and their parameters for tooling and runtime

Capabilities

Core Plugin Development

Essential interfaces and base classes for creating Maven plugins. Provides the fundamental Mojo contract and ready-to-use AbstractMojo base class with logging and context support.

public interface Mojo {
    String ROLE = Mojo.class.getName();
    void execute() throws MojoExecutionException, MojoFailureException;
    void setLog(Log log);
    Log getLog();
}

public abstract class AbstractMojo implements Mojo, ContextEnabled {
    public void setLog(Log log);
    public Log getLog();
    public Map getPluginContext();
    public void setPluginContext(Map pluginContext);
}

Core Plugin Development

Exception Handling

Exception classes for proper error reporting during plugin execution. Distinguishes between unexpected errors and expected failures to provide appropriate Maven build messages.

public class MojoExecutionException extends AbstractMojoExecutionException {
    public MojoExecutionException(String message);
    public MojoExecutionException(String message, Exception cause);
    public MojoExecutionException(String message, Throwable cause);
    public MojoExecutionException(Object source, String shortMessage, String longMessage);
}

public class MojoFailureException extends AbstractMojoExecutionException {
    public MojoFailureException(String message);
    public MojoFailureException(String message, Throwable cause);
    public MojoFailureException(Object source, String shortMessage, String longMessage);
}

public class MojoNotFoundException extends Exception {
    public MojoNotFoundException(String goal, PluginDescriptor pluginDescriptor);
    public String getGoal();
    public PluginDescriptor getPluginDescriptor();
}

Exception Handling

Logging System

Standardized logging interface for Maven plugins with support for debug, info, warn, and error levels. Integrates with Maven's output system and supports both message-only and message-with-throwable logging.

public interface Log {
    boolean isDebugEnabled();
    void debug(CharSequence content);
    void debug(CharSequence content, Throwable error);
    void debug(Throwable error);
    
    boolean isInfoEnabled();
    void info(CharSequence content);
    void info(CharSequence content, Throwable error);
    void info(Throwable error);
    
    boolean isWarnEnabled();
    void warn(CharSequence content);
    void warn(CharSequence content, Throwable error);
    void warn(Throwable error);
    
    boolean isErrorEnabled();
    void error(CharSequence content);
    void error(CharSequence content, Throwable error);
    void error(Throwable error);
}

Logging System

Plugin Descriptors

Metadata classes for describing plugins, mojos, and their parameters. Used by Maven tools, IDEs, and the runtime to understand plugin structure and configuration options.

public class PluginDescriptor extends ComponentSetDescriptor implements Cloneable {
    public String getGroupId();
    public String getArtifactId();
    public String getVersion();
    public String getGoalPrefix();
    public List<MojoDescriptor> getMojos();
    public MojoDescriptor getMojo(String goal);
    public void addMojo(MojoDescriptor mojoDescriptor) throws DuplicateMojoDescriptorException;
}

public class MojoDescriptor extends ComponentDescriptor<Mojo> implements Cloneable {
    public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session";
    public static final String MULTI_PASS_EXEC_STRATEGY = "always";
    
    public String getGoal();
    public String getPhase();
    public List<Parameter> getParameters();
    public Map<String, Parameter> getParameterMap();
}

Plugin Descriptors

Types

public interface ContextEnabled {
    void setPluginContext(Map pluginContext);
    Map getPluginContext();
}

public abstract class AbstractMojoExecutionException extends Exception {
    protected Object source;
    protected String longMessage;
    
    public String getLongMessage();
    public Object getSource();
}

public class SystemStreamLog implements Log {
    // Default Log implementation using System.out and System.err
}

public class DefaultLog implements Log {
    /**
     * Create DefaultLog wrapping Plexus logger
     * @param logger Plexus logger instance
     */
    public DefaultLog(Logger logger);
}