Maven Core classes - the core engine of Apache Maven build system
npx @tessl/cli install tessl/maven-org-apache-maven--maven-core@3.9.0Maven 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.
pom.xml dependencies or access via Maven runtimeimport 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;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());
}Maven Core follows a component-based architecture using Plexus dependency injection:
Maven interface orchestrates build execution through MavenSessionMavenProject represents project model with ProjectBuilder for constructionPluginManager and BuildPluginManager handle plugin lifecycle and executionLifecycleExecutor manages build phases and goalsRepositorySystem handles artifact resolution and deploymentExecutionListener and EventSpy provide build event notificationsCore 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();
}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;
}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;
}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();
}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";
}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();
}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();
}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();
}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);
}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();
}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
}