Skip to Main Content
Maven: The Definitive Guide
book

Maven: The Definitive Guide

by Sonatype Company
September 2008
Intermediate to advanced content levelIntermediate to advanced
470 pages
14h 22m
English
O'Reilly Media, Inc.
Content preview from Maven: The Definitive Guide

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.

To test how Nexus ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Apache Maven Cookbook

Apache Maven Cookbook

Raghuram Bharathan
Mastering Apache Maven 3

Mastering Apache Maven 3

Prabath Siriwardena
Learning Apache Maven

Learning Apache Maven

Kevin Bowersox

Publisher Resources

ISBN: 9780596517335Supplemental ContentErrata Page