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.
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.
- 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.
Before you begin, ensure you have the following prerequisites:
Follow these steps to set up the Maven repository mirroring and caching project:
- Clone the repository:
git clone https://github.com/hexboy/maven-mirror-tool.git
cd maven-mirror-tool
- Install dependencies using Yarn:
yarn install
- Duplicate the
config.yml
file and rename the copy toconfig.local.yml
in the project root directory. - Open the
config.local.yml
file. - Customize the
REPOSITORIES
array to include the Maven repositories you want to mirror and cache. - 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 #
- Start the Maven Repository Mirroring and Caching Tool:
yarn start
- 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 }
...
}
}
- Run your Gradle builds as usual. The tool will intercept and resolve dependencies from the local endpoint, caching them if needed.
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:
- Pull the Docker image:
docker pull hexboy2011/maven-mirror-tool:latest
- 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
-
-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.
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.
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.