Apache Maven Resolver

repository·master·Indexed 40 days ago

https://github.com/apache/maven-resolver

A core component of the Maven ecosystem responsible for resolving project dependencies, managing artifacts, and handling dependency graphs. It includes modules for API, SPI, and utilities, as well as specialized transports such as maven-resolver-transport-file for local storage simulation and maven-resolver-transport-url for lightweight artifact consumption using java.net.HttpURLConnection.

Tokens
19.6K
Snippets
27
Records
80
Agent score
100%

What's inside Maven Resolver

  1. Overview of Apache Maven Artifact Resolver

    master

    Apache Maven Artifact Resolver is a library designed for managing artifact repositories and performing dependency resolution. It provides the core logic for handling:

    • Local and Remote Repositories: Specifying where artifacts are stored and retrieved.
    • Developer Workspaces: Managing environments for development.
    • Artifact Transports: Moving artifacts between locations.
    • Artifact Resolution: The process of determining and fetching the required dependencies.

    Note that the core library is intended to be extended by concrete repository implementations. For example, to work with standard Maven repositories, you should use the Maven Artifact Resolver Provider.

  2. What is Resolver (formerly Aether)?

    master

    Resolver is an embeddable Java library designed for artifact resolution and deployment. It allows you to integrate Maven-like dependency resolution mechanisms into your own applications without embedding the entire Maven distribution or Plexus.

    Key capabilities include:

    • Fetching artifacts from remote repositories for local consumption.
    • Publishing local artifacts to remote repositories.
    • Providing a customizable framework for artifact resolution and deployment.
    • Supporting multithreaded environments (unlike the stateful singletons found in standard Maven).

    Note that Resolver Core is tool-agnostic and does not natively understand Maven repository formats. It relies on extensions to handle specific repository types.

  3. Overview of Maven Resolver URL Transport

    master

    The maven-resolver-transport-url is a lightweight, special transport implementation with limited HTTP capabilities. It is designed for applications running on Java 8+ that integrate the Maven Resolver strictly for consumption purposes (e.g., downloading artifacts).

    It serves as a middle ground between the JDK transport (which requires Java 11+) and the heavyweight apache-httpclient transport, making it ideal for environments where minimizing dependencies and resource usage is a priority.

    Important Limitation: This transport is not a fully functional transport. While it is highly effective for artifact consumption, it is not suitable for artifact deployment.

  4. What is Remote Repository Filtering (RRF)?

    master

    Remote Repository Filtering (RRF) is a feature in Maven Resolver that allows the resolver to filter artifacts by repository based on extensible criteria. Instead of the traditional "ordered loop" search (where Maven queries every repository in the effective POM until an artifact is found), RRF allows Maven to query only the repositories that are likely to contain the specific artifact.

    Benefits:

    • Faster builds: Reduces unnecessary queries to repositories that do not contain the artifact.
    • Privacy/Reduced Leakage: Prevents "leaking" artifact requests to remote repository operators (e.g., querying Maven Central for internal artifacts).
    • Build Stability: Avoids the need for "virtual" or "group" repositories in MRM (Maven Repository Managers), which can cause loss of artifact origin information and make projects un-buildable if the MRM is unavailable.
  5. Use Remote Included checksums via HTTP headers

    master

    The Remote Included strategy allows Resolver to retrieve the expected checksum within the same HTTP response used to download the artifact. This is efficient as it requires only one HTTP request.

    Requirements & Limitations:

    • This strategy only works with transport-http. It is not supported by transport-wagon.
    • You can enable or disable this behavior using the aether.connector.basic.includedChecksums configuration key.

    Supported Header Variants: Resolver automatically detects several unstandardized X- headers used by different providers:

    • Maven Central: x-checksum-sha1, x-checksum-md5
    • Google Mirror of Maven Central: x-goog-meta-checksum-sha1, x-goog-meta-checksum-md5
    • AWS S3: x-amz-meta-checksum-sha1, x-amz-meta-checksum-md5
  6. Understand the role and limitations of checksums in Maven Resolver

    master

    Maven Resolver uses checksums (typically SHA-1 and MD5) located next to target files in repositories to verify the integrity of downloaded artifacts and metadata.

    Important Security Note: Checksums are intended only for detecting transport errors and verifying integrity. They do not provide security, trust, or protection against man-in-the-middle or supply chain attacks. To ensure an artifact has not been tampered with, you must use digital signatures (e.g., via the Maven GPG Plugin).

  7. Customize dependency graph construction with extension points

    master

    Users can control how the dependency graph is built by providing custom implementations of the following interfaces when creating a repository system session:

    • org.eclipse.aether.collection.DependencySelector: Used to exclude dependencies from the graph (e.g., excluding optional dependencies or dependencies with specific unwanted scopes).
    • org.eclipse.aether.collection.DependencyManager: Applies dependency management rules to the graph.
    • org.eclipse.aether.collection.VersionFilter: Filters the list of matching versions for a dependency (e.g., banning SNAPSHOT versions).
    • org.eclipse.aether.collection.DependencyTraverser: Controls the recursion of the process (e.g., deciding whether to include dependencies of a specific artifact type like a WAR file).
    • org.eclipse.aether.collection.DependencyGraphTransformer: A chain of transformers used to convert a "dirty graph" (containing duplicates, conflicts, or cycles) into a "resolved graph" by pruning unwanted parts or resolving version/scope conflicts.
  8. Extend checksum algorithms via the Checksum SPI

    master

    Maven Resolver uses a Service Provider Interface (SPI) to manage checksum algorithms instead of exposing java.security.MessageDigest directly. This prevents the accidental addition of non-standard checksums while allowing controlled extensions.

    The SPI currently supports the following four case-sensitive algorithms:

    • MD5
    • SHA-1
    • SHA-256
    • SHA-512

    If you need to support a checksum algorithm not provided by Maven Resolver, you can extend the system by creating a new factory component for that algorithm and registering it via the SPI.

  9. Handle shared access to the Local Repository

    master

    When multiple threads, processes, or hosts access the same local repository, concurrent read/write operations can lead to corrupted or incomplete data.

    To prevent this, Maven Resolver provides a pluggable Named Locks API. Available implementations include:

    • Multi-threaded: Locking within a single JVM (default).
    • Multi-process: Using file system advisory locking.
    • Multi-host: Using distributed locking via Hazelcast or Redisson (requires a cluster).
  10. Core Modules of Maven Artifact Resolver

    master

    The Maven Artifact Resolver project is composed of several modules that separate the public API, service provider interfaces, and specific transport implementations:

    • maven-resolver-api: The public API for interacting with the resolver.
    • maven-resolver-spi: Service Provider Interfaces for extending the resolver.
    • maven-resolver-util: Utility classes used across the project.
    • maven-resolver-impl: The core implementation of the resolver logic.
    • maven-resolver-connector-basic: Basic connector implementation.
    • Transport Modules:
      • maven-resolver-transport-file: File-based transport.
      • maven-resolver-transport-classpath: Classpath-based transport.
      • maven-resolver-transport-wagon: Wagon-based transport.
      • maven-resolver-transport-http: HTTP-based transport.
    • maven-resolver-test-util: Utilities for testing resolver implementations.
  11. How Repository Connectors, Layouts, and Transporters work together

    master

    The deployment workflow in Maven Resolver follows a layered abstraction model:

    1. RepositoryConnector: The high-level component (e.g., BasicRepositoryConnector) that manages the deployment logic.
    2. RepositoryLayout: Responsible for determining the destination path. It uses methods like getLocation(Artifact, true) or getLocation(Metadata, true) to calculate the correct URL based on the repository type (e.g., Maven2RepositoryLayoutFactory for Maven 2 layouts).
    3. Transporter: The low-level component that performs the actual I/O. It receives the location from the layout and executes the write/upload operation.