Where Are Maven Core Implementations Located? A Deep Dive into apache/maven

The Maven core implementations are located in the impl/maven-core module of the Apache Maven repository, specifically under impl/maven-core/src/main/java/org/apache/maven/, containing concrete classes that handle project building, dependency resolution, and plugin execution.

Apache Maven is a software project management and comprehension tool that relies on a central core to execute build lifecycles. The Maven core implementations provide the concrete logic behind the public APIs, driving everything from POM parsing to artifact resolution. This module serves as the engine that the Maven CLI and embedder invoke to perform actual build work.

Location of Maven Core Implementations

The heart of Apache Maven resides in the impl/maven-core module. This directory contains the concrete implementations of the org.apache.maven.* packages that drive the build lifecycle, project model handling, and settings processing.

All core classes live under:


impl/maven-core/src/main/java/org/apache/maven/

The module's pom.xml at impl/maven-core/pom.xml defines dependencies on Aether (for artifact resolution) and Plexus (for dependency injection), assembling the final JAR used by the Maven CLI.

Key Components Inside impl/maven-core

Project Building and Model Handling

The project building subsystem parses pom.xml files and constructs the in-memory project representation.

Dependency Resolution

The dependency resolution engine handles transitive dependencies and builds the artifact graph.

Plugin Management

Plugin discovery and validation occur through specialized resolvers and validators.

Configuration and Runtime Support

Supporting infrastructure includes settings processing and repository integration.

Architecture Flow: How the Core Fits Together

The Maven core implementations operate in a specific sequence during build execution:

  1. CLI to Core: The command-line interface in maven-embedder creates a MavenExecutionRequest and delegates to the core implementation.
  2. Project Building: The ProjectBuilder constructs a full MavenProject model by parsing the POM and resolving inheritance.
  3. Dependency Resolution: The DefaultProjectDependenciesResolver uses the RepositorySystem (Aether) to download and resolve the project dependency graph.
  4. Plugin Resolution: The DefaultPluginPrefixResolver maps plugin prefixes to artifacts, while DefaultMavenPluginValidator ensures compatibility.
  5. Lifecycle Execution: The core drives lifecycle phases (validate, compile, test, etc.) via the MavenLifecycleExecutor (located in impl/maven-impl but reliant on core services).

Working with Maven Core Classes

While typical usage goes through higher-level APIs like Maven or MavenCli, you can interact with core classes directly for embedded scenarios.

Building a Project Programmatically

import org.apache.maven.project.DefaultProjectBuilder;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingResult;
import org.apache.maven.project.MavenProject;
import java.io.File;

MavenExecutionRequest request = new DefaultMavenExecutionRequest()
    .setBaseDirectory(new File("my-project"))
    .setUserSettingsFile(new File(System.getProperty("user.home"), ".m2/settings.xml"));

ProjectBuilder builder = new DefaultProjectBuilder();
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest()
    .setProcessPlugins(true)
    .setRepositorySession(RepositorySystemSessionFactory.newSession());

ProjectBuildingResult result = builder.build(new File("my-project/pom.xml"), pbr);
MavenProject project = result.getProject();
System.out.println("Project: " + project.getId());

Source: DefaultProjectBuilder implementation in impl/maven-core.

Resolving a Plugin Prefix

import org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver;
import org.apache.maven.plugin.prefix.PluginPrefixRequest;
import org.apache.maven.plugin.prefix.PluginPrefixResult;

PluginPrefixRequest prefixReq = new PluginPrefixRequest()
    .setPrefix("compiler")
    .setPom(project.getFile())
    .setRepositorySession(session);

PluginPrefixResult prefixRes = new DefaultPluginPrefixResolver()
    .resolve(prefixReq);
System.out.println("Plugin artifact: " + prefixRes.getPluginArtifact());

Source: DefaultPluginPrefixResolver in impl/maven-core.

Validating a Plugin Before Execution

import org.apache.maven.plugin.internal.DefaultMavenPluginValidator;
import org.apache.maven.plugin.MavenPluginValidator;

MavenPluginValidator validator = new DefaultMavenPluginValidator();
MavenPluginValidationResult vRes = validator.validate(plugin, project, session);
if (!vRes.isValid()) {
    throw new MavenExecutionException("Invalid plugin configuration");
}

Source: DefaultMavenPluginValidator in impl/maven-core.

Summary

  • The Maven core implementations reside in the impl/maven-core module, specifically under impl/maven-core/src/main/java/org/apache/maven/.
  • DefaultProjectBuilder and MavenProject handle POM parsing and in-memory model representation.
  • DefaultProjectDependenciesResolver manages transitive dependency resolution using Aether.
  • DefaultPluginPrefixResolver and DefaultMavenPluginValidator handle plugin discovery and compatibility checking.
  • The core classes are used by the Maven CLI and embedder to execute the full build lifecycle from project initialization through plugin execution.

Frequently Asked Questions

What is the difference between maven-core and maven-impl?

The impl/maven-core module contains the concrete implementations of project building, dependency resolution, and plugin management classes. The impl/maven-impl module contains higher-level orchestration components like Maven and MavenLifecycleExecutor that coordinate these core services during build execution.

How does Maven resolve dependencies programmatically?

Maven uses the DefaultProjectDependenciesResolver class located in impl/maven-core/src/main/java/org/apache/maven/project/. This class constructs a dependency graph, resolves conflicts, and downloads artifacts using the Eclipse Aether repository system through the RepositorySystemSession created by RepositorySystemSessionFactory.

Where is the POM parsing logic located in Maven?

The primary POM parsing logic resides in DefaultProjectBuilder.java at impl/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java. This class reads the pom.xml, resolves parent POMs, validates the model, and produces a MavenProject instance representing the build configuration.

Can I use Maven core classes in my own application?

Yes, you can embed Maven by depending on the maven-core artifact and using classes like ProjectBuilder and DefaultProjectDependenciesResolver. However, you must configure a RepositorySystemSession and Plexus container (CDI) properly, as these core implementations rely on dependency injection and the Aether repository system to function.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →