or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-execution.mdexception-handling.mdindex.mdlifecycle-management.mdplugin-system.mdproject-management.mdrepository-system.md
tile.json

tessl/maven-org-apache-maven--maven-core

Maven Core classes - the core engine of Apache Maven build system

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

To install, run

npx @tessl/cli install tessl/maven-org-apache-maven--maven-core@3.9.0

index.mddocs/

Maven Core

Maven Core provides the foundational classes and interfaces for the Apache Maven build system. It serves as the core engine that orchestrates project building, dependency management, plugin execution, and lifecycle management for Java projects and beyond.

Package Information

  • Package Name: org.apache.maven:maven-core
  • Package Type: Maven
  • Language: Java
  • Installation: Add to pom.xml dependencies or access via Maven runtime
  • Version: 3.9.11

Core Imports

import org.apache.maven.Maven;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;

Plexus Component Access:

import org.codehaus.plexus.component.annotations.Component;
import org.apache.maven.Maven;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.plugin.PluginManager;

@Component
private Maven maven;

@Component
private ProjectBuilder projectBuilder;

@Component 
private PluginManager pluginManager;

Basic Usage

import org.apache.maven.Maven;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.project.MavenProject;

// Create and configure execution request
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setPom(new File("pom.xml"));
request.setGoals(Arrays.asList("compile", "test"));
request.setBaseDirectory(new File("."));

// Execute Maven build
Maven maven = container.lookup(Maven.class);
MavenExecutionResult result = maven.execute(request);

// Process results
if (result.hasExceptions()) {
    for (Throwable exception : result.getExceptions()) {
        System.err.println("Build error: " + exception.getMessage());
    }
} else {
    System.out.println("Build successful");
    MavenProject project = result.getProject();
    System.out.println("Built project: " + project.getName());
}

Architecture

Maven Core follows a component-based architecture using Plexus dependency injection:

  • Execution Layer: Maven interface orchestrates build execution through MavenSession
  • Project Layer: MavenProject represents project model with ProjectBuilder for construction
  • Plugin Layer: PluginManager and BuildPluginManager handle plugin lifecycle and execution
  • Lifecycle Layer: LifecycleExecutor manages build phases and goals
  • Repository Layer: RepositorySystem handles artifact resolution and deployment
  • Event System: ExecutionListener and EventSpy provide build event notifications

Capabilities

Maven Execution

Core Maven build execution and session management.

public interface Maven {
    MavenExecutionResult execute(MavenExecutionRequest request);
}

public interface MavenExecutionRequest {
    // Build Configuration
    MavenExecutionRequest setPom(File pom);
    MavenExecutionRequest setGoals(List<String> goals);
    MavenExecutionRequest setBaseDirectory(File baseDirectory);
    
    // Repository Configuration  
    MavenExecutionRequest setLocalRepository(ArtifactRepository localRepository);
    MavenExecutionRequest setRemoteRepositories(List<ArtifactRepository> repositories);
    
    // Reactor Configuration
    String REACTOR_FAIL_FAST = "FAIL_FAST";
    String REACTOR_FAIL_AT_END = "FAIL_AT_END"; 
    String REACTOR_FAIL_NEVER = "FAIL_NEVER";
    MavenExecutionRequest setReactorFailureBehavior(String failureBehavior);
}

public class MavenSession {
    public MavenProject getCurrentProject();
    public List<MavenProject> getProjects();
    public MavenExecutionRequest getRequest();
    public RepositorySystemSession getRepositorySession();
    public Map<String, Object> getUserProperties();
    public boolean isParallel();
}

Core Execution

Project Management

Project model access, building, and dependency resolution.

public class MavenProject {
    public Artifact getArtifact();
    public Model getModel();
    public List<Dependency> getDependencies();
    public List<String> getCompileSourceRoots();
    public List<String> getTestClasspathElements() throws DependencyResolutionRequiredException;
    public File getBasedir();
    public String getName();
    public String getVersion();
}

public interface ProjectBuilder {
    ProjectBuildingResult build(File projectFile, ProjectBuildingRequest request) 
        throws ProjectBuildingException;
    List<ProjectBuildingResult> build(List<File> projectFiles, boolean recursive,
        ProjectBuildingRequest request) throws ProjectBuildingException;
}

Project Management

Plugin System

Plugin management, execution, and caching mechanisms.

public interface MavenPluginManager {
    PluginDescriptor getPluginDescriptor(Plugin plugin, List<RemoteRepository> repositories,
        RepositorySystemSession session) throws PluginDescriptorParsingException, InvalidPluginDescriptorException;
    ClassRealm setupPluginRealm(PluginDescriptor pluginDescriptor, MavenSession session,
        ClassLoader parent, List<String> imports, DependencyFilter filter) throws PluginManagerException;
    void getConfiguredMojo(Class<?> mojoInterface, MavenSession session, MojoExecution mojoExecution)
        throws PluginConfigurationException, PluginContainerException;
}

public interface BuildPluginManager {
    PluginDescriptor loadPlugin(Plugin plugin, List<RemoteRepository> repositories,
        RepositorySystemSession session) throws PluginNotFoundException, PluginResolutionException;
    void executeMojo(MavenSession session, MojoExecution execution) throws MojoFailureException, MojoExecutionException;
    ClassRealm getPluginRealm(MavenSession session, PluginDescriptor pluginDescriptor) throws PluginManagerException;
}

Plugin System

Lifecycle Management

Build lifecycle execution and phase management.

public interface LifecycleExecutor {
    MavenExecutionPlan calculateExecutionPlan(MavenSession session, String... tasks) throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException, InvalidPluginDescriptorException;
    void execute(MavenSession session);
    List<MavenProject> executeForkedExecutions(MojoExecution mojoExecution, MavenSession session) throws LifecycleExecutionException;
}

public class MavenExecutionPlan implements Iterable<MojoExecution> {
    public List<MojoExecution> getMojoExecutions();
    public Iterator<MojoExecution> iterator();
    public int size();
}

Lifecycle Management

Repository System

Artifact resolution, transfer, and repository operations.

public interface RepositorySystem {
    ArtifactResult resolve(RepositorySystemSession session, ArtifactRequest request) throws ArtifactResolutionException;
    List<ArtifactResult> resolveArtifacts(RepositorySystemSession session, Collection<? extends ArtifactRequest> requests) throws ArtifactResolutionException;
    void publish(RepositorySystemSession session, Collection<? extends PublishRequest> requests) throws PublishException;
    ArtifactDescriptorResult readArtifactDescriptor(RepositorySystemSession session, ArtifactDescriptorRequest request) throws ArtifactDescriptorException;
    
    static final String DEFAULT_LOCAL_REPO_ID = "local";
    static final String DEFAULT_REMOTE_REPO_URL = "https://repo.maven.apache.org/maven2";
}

Repository System

Exception Handling

Comprehensive exception handling for Maven operations.

public class MavenExecutionException extends Exception {
    public MavenExecutionException(String message, Throwable cause);
}

public class ProjectBuildingException extends Exception {
    public String getProjectId();
    public File getPomFile();
    public List<ProjectBuildingResult> getResults();
}

public class PluginExecutionException extends PluginManagerException {
    public MojoExecution getMojoExecution();
    public MavenProject getProject();
}

Exception Handling

Toolchain Management

Java toolchain management for build environments.

public interface ToolchainManager {
    List<Toolchain> getToolchains(MavenSession session, String type, Map<String, String> requirements);
    Toolchain getDefaultToolchain(MavenSession session, String type);
}

public interface JavaToolchain extends Toolchain {
    String getJavaHome();
    String findTool(String toolName);
}

public class JavaToolchainFactory implements ToolchainFactory {
    public Toolchain createToolchain(PersistedToolchain model) throws MisconfiguredToolchainException;
    public Toolchain createDefaultToolchain();
}

Utility APIs

Maven runtime information and utility functions.

public interface RuntimeInformation {
    String getMavenVersion();
    String getApplicationName();
    File getMavenHome();
}

public class RepositoryUtils {
    public static org.eclipse.aether.artifact.Artifact toArtifact(org.apache.maven.artifact.Artifact artifact);
    public static org.apache.maven.artifact.Artifact toArtifact(org.eclipse.aether.artifact.Artifact artifact);
    public static org.eclipse.aether.repository.RemoteRepository toRepo(ArtifactRepository repository);
    public static List<org.eclipse.aether.repository.RemoteRepository> toRepos(List<ArtifactRepository> repositories);
}

public interface ArtifactFilterManager {
    ArtifactFilter getArtifactFilter();
    ArtifactFilter getCoreArtifactFilter();
}

Types

Core Execution Types

public interface MavenExecutionResult {
    MavenProject getProject();
    List<MavenProject> getTopologicallySortedProjects();
    DependencyResolutionResult getDependencyResolutionResult();
    List<Throwable> getExceptions();
    Map<MavenProject, BuildSummary> getBuildSummary(MavenProject project);
    boolean hasExceptions();
}

public class MojoExecution {
    public String getExecutionId();
    public Plugin getPlugin();
    public String getGoal();
    public String getLifecyclePhase();
    public MojoDescriptor getMojoDescriptor();
    public PlexusConfiguration getConfiguration();
}

public interface ExecutionListener {
    void projectDiscoveryStarted(ExecutionEvent event);
    void sessionStarted(ExecutionEvent event);
    void sessionEnded(ExecutionEvent event);
    void projectSkipped(ExecutionEvent event);
    void projectStarted(ExecutionEvent event);
    void projectSucceeded(ExecutionEvent event);
    void projectFailed(ExecutionEvent event);
    void mojoSkipped(ExecutionEvent event);
    void mojoStarted(ExecutionEvent event);
    void mojoSucceeded(ExecutionEvent event);
    void mojoFailed(ExecutionEvent event);
    void forkStarted(ExecutionEvent event);
    void forkSucceeded(ExecutionEvent event);
    void forkFailed(ExecutionEvent event);
    void forkedProjectStarted(ExecutionEvent event);
    void forkedProjectSucceeded(ExecutionEvent event);
    void forkedProjectFailed(ExecutionEvent event);
}

Repository Types

public interface ArtifactRepository {
    String getId();
    String getUrl();
    ArtifactRepositoryLayout getLayout();
    ArtifactRepositoryPolicy getSnapshots();
    ArtifactRepositoryPolicy getReleases();
    boolean isUniqueVersion();
    boolean isBlacklisted();
}

public interface ArtifactTransferListener {
    void transferInitiated(ArtifactTransferEvent event);
    void transferStarted(ArtifactTransferEvent event);
    void transferProgress(ArtifactTransferEvent event);
    void transferCompleted(ArtifactTransferEvent event);
}

public class ArtifactTransferEvent {
    public static final int TRANSFER_INITIATED = 1;
    public static final int TRANSFER_STARTED = 2; 
    public static final int TRANSFER_COMPLETED = 3;
    public static final int TRANSFER_ERROR = 4;
    
    public Artifact getArtifact();
    public Exception getException();
    public File getLocalFile();
    public ArtifactRepository getRepository();
}

Toolchain Types

public interface Toolchain {
    String getType();
    String findTool(String toolName);
}

public interface ToolchainManager {
    Toolchain getToolchainFromBuildContext(String type, MavenSession session);
    List<Toolchain> getToolchains(MavenSession session, String type, Map<String, String> requirements);
}

public interface JavaToolchain extends Toolchain {
    // Java-specific toolchain interface that extends base Toolchain
}