Configure Maven Repositories and Mirrors
· One min read
Maven resolves dependencies from repositories. A mirror in settings.xml can redirect requests to a faster or internally controlled repository manager.
<settings>
<mirrors>
<mirror>
<id>company-mirror</id>
<name>Company Maven Mirror</name>
<url>https://repo.example.com/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
mirrorOf=* routes all repository requests through the mirror. In an enterprise environment, this supports caching, license review, malware scanning, and reproducible builds.
Credentials belong in settings.xml, not in a committed pom.xml:
<servers>
<server>
<id>company-mirror</id>
<username>${env.MAVEN_REPO_USER}</username>
<password>${env.MAVEN_REPO_PASSWORD}</password>
</server>
</servers>
When downloads fail, run Maven with -X, inspect the effective settings, verify proxy and TLS configuration, confirm that the artifact coordinates exist, and remove only the affected corrupted cache directory rather than deleting the entire local repository.