Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring a Maven Private Repository with Nexus

Tech 1

Installation and Initialization

Download the Nexus OSS bundle (version 2.14.2-01) from Sonatype.

# Create system user
sudo useradd nexus_user
sudo passwd nexus_user

# Switch to new user
su - nexus_user

# Prepare directories and extract
mkdir -p /opt/nexus_repo
cd /opt/nexus_repo
tar xvzf nexus-2.14.2-01-bundle.tar.gz
cd nexus-2.14.2-01/bin

# Launch service
./nexus start

Access the web interface at http://127.0.0.1:8081/nexus/.

Repository Configuration

Enable Remote Indexing

Authenticate with default credantials (admin/admin123). Navigate to Administration > Repositories. For repositories Apache Snapshots and Central, set Download Remote Indexes to true in the configuration panel. Right-click each repository and select Repair Index.

Configure Proxy Repository

Create a new proxy repository:

  • Repository ID: aliyun-mirror
  • Remote Storage: http://maven.aliyun.com/nexus/content/groups/public/
  • Checksum Policy: Ignore

Add this repository to the public group (Public Repositories).

Maven Configuration

Global Settings (settings.xml)

Modify Maven's global configuraton file (e.g., ~/.m2/settings.xml):

<settings>
  <servers>
    <server>
      <id>corp-releases</id>
      <username>deployer</username>
      <password>strongPassword</password>
    </server>
    <server>
      <id>corp-snapshots</id>
      <username>deployer</username>
      <password>strongPassword</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>central-proxy</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>internal-repos</id>
      <repositories>
        <repository>
          <id>group-repo</id>
          <url>http://localhost:8081/nexus/content/groups/public</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>internal-repos</activeProfile>
  </activeProfiles>
</settings>

Project Configuration (pom.xml)

Declare repository and deployment targets:

<distributionManagement>
  <repository>
    <id>corp-releases</id>
    <name>Corporate Release Archive</name>
    <url>http://localhost:8081/nexus/content/repositories/releases</url>
  </repository>
  <snapshotRepository>
    <id>corp-snapshots</id>
    <name>Corporate Snapshot Archive</name>
    <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
  </snapshotRepository>
</distributionManagement>

<repositories>
  <repository>
    <id>group-repo</id>
    <name>Combined Repository</name>
    <url>http://localhost:8081/nexus/content/groups/public</url>
    <releases><enabled>true</enabled></releases>
    <snapshots><enabled>true</enabled></snapshots>
  </repository>
</repositories>
Tags: mavennexus

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.