Configuring Maven to Use Nexus Repositories
To use Nexus, you will configure Maven to check Nexus instead of the public repositories. To do so, youâll need to edit your mirror settings in your ~/.m2/settings.xml file. First, weâre going to demonstrate how to configure Maven to consult your Nexus installation instead of retrieving artifacts directly from the central Maven repository. After we override the central repository and demonstrate that Nexus is working, weâll circle back to provide a more sensible set of settings that will cover both releases and snapshots.
Using the Nexus Central Proxy Repository
To configure Maven to consult Nexus instead of the central Maven repository, add the mirror settings from Example 16-1 to your ~/.m2/settings.xml file.
Example 16-1. Configuring Maven settings for Nexus (~/.m2/settings.xml)
<?xml version="1.0"?> <settings> ... <mirrors> <mirror> <id>Nexus</id> <name>Nexus Public Mirror</name> <url>http://localhost:8081/nexus/content/groups/public</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> ... </settings>
Once youâve configured Nexus to be the mirror for all repositories, Maven will now consult the local installation of Nexus instead of going out to the central Maven repository. If Nexus has the artifact requested, the artifact will be served from the local Nexus installation. If Nexus does not have the artifact, Nexus will retrieve it from the remote repository and then add it to the local mirror of that remote repository.
Get Maven: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.