Configuring a Maven Private Repository with Nexus
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>