Skip to content

A solution for mirroring and local caching multiple Maven repositories.

License

Notifications You must be signed in to change notification settings

hexboy/maven-mirror-tool

Repository files navigation

Maven Repository Mirroring and Caching Tool

This repository provides a solution for mirroring and caching multiple Maven repositories, providing a unified endpoint.This endpoint can then be utilized in gradle.build files to streamline your Gradle-based projects.

Table of Contents

Introduction

Managing multiple Maven repositories can become cumbersome, especially when dealing with Gradle projects. This project aims to simplify the process by creating a unified endpoint that mirrors and caches the artifacts from various Maven repositories. This can lead to reduced build times and improved overall development efficiency.

Features

  • Unified Endpoint: Access all your Maven dependencies through a single, local endpoint.
  • Caching: Store downloaded artifacts locally to minimize redundant network requests.
  • Mirroring: Mirror remote Maven repositories for offline development and increased reliability.
  • Customization: Configure the tool to handle specific repositories and dependencies.

Getting Started

Prerequisites

Before you begin, ensure you have the following prerequisites:

Installation

Follow these steps to set up the Maven repository mirroring and caching project:

  1. Clone the repository:
git clone https://github.com/hexboy/maven-mirror-tool.git
cd maven-mirror-tool
  1. Install dependencies using Yarn:
yarn install

Configuration

  1. Duplicate the config.yml file and rename the copy to config.local.yml in the project root directory.
  2. Open the config.local.yml file.
  3. Customize the REPOSITORIES array to include the Maven repositories you want to mirror and cache.
  4. Modify any other settings as needed, such as port number or caching options or proxy servers.

Here's an example configuration snippet:

PROXIES:
  fodev: # The key is utilized in the proxy section of the repository configuration.
    host: fodev.org
    port: 8118
    protocol: http # The following protocols are supported: http, https, and socks.

  private:
    host: myserver.com
    port: 1080
    protocol: socks
    auth:                  # optional: Authentication info
      username: myusername #
      password: mypassword #

  local:
    host: 127.0.0.1
    port: 1080
    protocol: socks

REPOSITORIES:
  - name: central
    url: https://repo1.maven.org/maven2
    fileTypes:   # optional: FileTypes can be specified to be cached.
      - '.jar'   #
      - '.aar'   #
    proxy: fodev # optional: Select a proxy server

  - name: private-repo
    url: https://repo.mycompany.com/maven
    auth:                  # optional: Authentication info
      username: myusername #
      password: mypassword #

Usage

  1. Start the Maven Repository Mirroring and Caching Tool:
yarn start
  1. Update your Gradle build.gradle files to use the local endpoint for Maven dependencies:
buildscript {
    repositories {
        mavenLocal();
        maven { url "http://127.0.0.1:8008/v1"; allowInsecureProtocol true } // Replace with your configured port
        ...
    }
}
allprojects {
    buildscript {
        repositories {
            mavenLocal()
            maven { url "http://127.0.0.1:8008/v1"; allowInsecureProtocol true }
            ...
        }
    }
    repositories {
        mavenLocal()
        maven { url "http://127.0.0.1:8008/v1"; allowInsecureProtocol true }
        ...
    }
}
  1. Run your Gradle builds as usual. The tool will intercept and resolve dependencies from the local endpoint, caching them if needed.

Using the Docker Image

You can also run the Maven Repository Mirroring and Caching Tool using Docker. This can simplify deployment and ensure consistency across different environments.

To use the Docker image hexboy2011/maven-mirror-tool:latest, follow these steps:

  1. Pull the Docker image:
docker pull hexboy2011/maven-mirror-tool:latest
  1. Run the Docker container, mapping port 8008 and binding the cache directory:
docker run -d \
-p 8008:8008 \
-v /your/custom/cache/dir:/home/node/app/local-cache \
-v /your/config.local.yml:/home/node/app/config.local.yml \
hexboy2011/maven-mirror-tool:latest

In this example

  • -d: Starts the container as a daemon, running it in the background.

  • -p 8008:8008: Maps port 8008 on your host to port 8008 in the container.

  • -v /your/custom/cache/dir:/home/node/app/local-cache: Binds the directory /your/custom/cache/dir on your host to /home/node/app/local-cache in the container, allowing the container to store cached artifacts locally.

  • -v /your/config.local.yml:/home/node/app/config.local.yml: Binds the file /your/config.local.yml on your host to /home/node/app/config.local.yml in the container, allowing the container to use your custom config file.

Contributing

Contributions are welcome! If you find any issues or would like to enhance the project, feel free to submit a pull request. Please follow the existing code style and provide clear commit messages.

License

This project is licensed under the MIT License, allowing you to use, modify, and distribute the code freely. Make sure to read and understand the license terms before using the project.


By following this README, you should be able to set up and use the Maven Repository Mirroring and Caching Tool for your Gradle projects seamlessly. If you encounter any issues or have further questions, don't hesitate to reach out to the project contributors.

About

A solution for mirroring and local caching multiple Maven repositories.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published