RepoFlow Team · June 10, 2025
Mirror Maven Central Repository
Learn how to mirror mirror maven central repository for offline builds and secure environments using wget
If you are managing Java applications in isolated or secure environments, such as air-gapped networks, regulated industries, or internal CI/CD pipelines, having full local access to Maven artifacts can greatly improve build reliability and speed.
This guide explains how to safely and efficiently mirror the Maven Central repository to your internal infrastructure. Mirroring gives you full control over artifact availability, ensures consistent builds, and removes reliance on external servers.
This guide explains how to safely and efficiently mirror the Maven Central repository to your internal infrastructure. Mirroring gives you full control over artifact availability, ensures consistent builds, and removes reliance on external servers.
⚠️ Important Notice
The script below uses a modified User-Agent and ignores
More importantly, at the time of writing this guide, mirroring the entire Maven Central repository is against their terms of service - see here.
If you wish to mirror the full repository, you must first contact Sonatype and coordinate with them, as they state in their terms.
Attempting to do this without coordination may result in your IP being blocked or rate-limited. For most users, mirroring specific small parts of the repository (as also explained in this guide) is more practical and compliant.
robots.txt
, which is not a friendly behavior toward Maven Central. More importantly, at the time of writing this guide, mirroring the entire Maven Central repository is against their terms of service - see here.
If you wish to mirror the full repository, you must first contact Sonatype and coordinate with them, as they state in their terms.
Attempting to do this without coordination may result in your IP being blocked or rate-limited. For most users, mirroring specific small parts of the repository (as also explained in this guide) is more practical and compliant.
Recommendations
In many cases, it is better to mirror only the specific groups you need, which significantly reduces storage requirements and sync times.
Additionally, periodically update your mirror with incremental syncs to keep it current without having to redownload the entire repository.
Additionally, periodically update your mirror with incremental syncs to keep it current without having to redownload the entire repository.
Prerequisites
You will need:
- A Linux machine or macOS with enough storage space (Maven Central is large)
-
wget
installed
Mirroring the Maven Central Repository
We will use
wget
to recursively download the Maven Central tree. This method works well for simple setups where you want a local copy of selected parts or the full repository.Example: Full Mirror Script
#!/bin/bash
# You must coordinate with Maven Central before running this script.
# Create the mirror directory
mkdir -p ./maven_mirror
# Base Maven repo URL
BASE_URL="https://repo1.maven.org/maven2/"
# Log file to track progress (optional)
LOG_FILE="./maven_mirror/mirror.log"
# Max depth (unlimited)
MAX_DEPTH=inf
# Start message
echo "==================================================="
echo "Starting FULL Maven Central mirror from: $BASE_URL"
echo "Target directory: ./maven_mirror"
echo "==================================================="
# Run wget — full tree
# WARNING: This sets a custom User-Agent and ignores robots.txt.
# You must coordinate with Maven Central first!!!
wget -P ./maven_mirror -r -nH -np --reject html \
--user-agent="MavenMirrorScript/1.0" \
--execute robots=off \
"https://repo1.maven.org/maven2/"
# Final message
echo -e "\n\n Maven FULL mirror complete!"
echo "Mirror stored in: ./maven_mirror"
echo "==================================================="
Example: Mirror Specific Maven Group (Recommanded)
wget -P ./maven_mirror -r -nH -np --reject html \
--user-agent="MavenMirrorScript/1.0" \
--execute robots=off \
--limit-rate=1M \ # Limit download speed to 1MB/s to be respectful to Maven Central servers
"https://repo1.maven.org/maven2/org/apache/commons/"
Notes on Maven Repository Structure
After syncing, the Maven repository follows a simple directory hierarchy:
Install apt-mirror:
/your-local-mirror/groupId/artifactId/version/
Example:
./maven_mirror/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.jar
./maven_mirror/org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.pom
Final Notes
Mirroring the entire Maven Central repository is an extreme use case and must be coordinated with Sonatype in advance, as it is against their terms of service. In most cases, mirroring only the specific groups you need is more practical and compliant. Please use this guide responsibly.