A Deep Dive Into Nexus Artifact Repository: Managing Artifacts, Integrating with Maven, and Streamlining CI/CD Pipelines
📌 Introduction
Nexus Repository Manager is a powerful tool in DevOps and software development workflows, especially when dealing with dependencies, build artifacts, and secure software delivery.
Let’s start with answering the ❓ Why and ❓ What, and then we’ll move to the implementation part.
❓ WHY Do We Need a Repository Manager?
📦 Centralized Artifact Storage
⚡ Improves Build Stability and Speed
🔁 Internal Artifact Versioning & Sharing
🔐 Security & Governance
🤖 Supports CI/CD Automation
📦 WHAT is an Artifact Repository?
🔍 WHAT is Nexus Repository Manager?
🌐 Public vs Private Artifact Repository Managers
🟢 Public Repository Managers
🔒 Private Repository Managers
⭐ Key Features of Nexus Repository
⚙️ HOW Does Nexus Help in Real-World DevOps Workflows?
🧑💻 1. Development & Build Phase
🚀 2. Publish Phase (CI/CD)
📥 3. Deployment Phase
🔄 Alternatives to Nexus
While Nexus is one of the most popular artifact managers, others include:
🏗️ Types of Repositories in Nexus
Nexus supports 3 main types:
📤 1. Hosted Repositories – Where you publish your own stuff
🔁 2. Proxy Repositories – Cache public dependencies locally
🧩 3. Group Repositories – Combine hosted + proxy under one URL
🧑🔧 Users and Roles in Nexus
Nexus offers robust user management and role-based access control (RBAC):
👤 Users
🛡️ Roles
💡 Best Practices:
💡 Pro Tips & Best Practices
☕ Understanding Maven: The Backbone of Java Build Automation
❓ WHY Do We Need Maven?
Before Maven, Java developers faced several pain points:
💡 Maven solves these problems elegantly by providing:
✅ Automated project builds: (compile → test → package → deploy) ✅ Dependency management using public/remote repositories ✅ Standardized directory structure and conventions across teams ✅ Integration with CI/CD tools and artifact repositories like Nexus
ჲ WHAT is Maven?
Apache Maven is a powerful build automation and dependency management tool for Java projects. It promotes “convention over configuration” to streamline the software development lifecycle.
🔧 Core Highlights:
🔀 HOW Does Maven Work?
When you execute commands like:
mvn install
Maven triggers a lifecycle defined in your pom.xml, running through a sequence of build phases.
🔄 Maven Build Lifecycle
Maven has 3 major lifecycles:
We’ll focus on the default lifecycle as it handles full build automation:
💼 Example:
mvn clean install
📚 Maven Repositories
Maven interacts with different types of repositories to fetch or publish artifacts:
Dependency Resolution Order:
📄 What is pom.xml?
The pom.xml file (Project Object Model) is the heart of a Maven project. It:
⚡ Everything Maven does is influenced by the pom.xml file.
🏦 What is the .m2 Folder?
.m2 is Maven’s default user home directory. It holds:
🏦 Local vs Remote Repositories
🏦 Local Repository
Location: ~/.m2/repository
Used to:
💡 Checked first before contacting remote repos.
🌐 Remote Repository
📉 What is settings.xml?
A powerful configuration file that controls Maven's global behavior.
📍 Location:
✅ Common Uses:
📈 Publishing Artifact to Nexus using Maven
📅 Step 1: Add Maven Deploy Plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
</plugin>
🔹 Step 2: Add Distribution Management
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshot</id>
<url>http://192.168.0.2:8081/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>nexus-release</id>
<url>http://192.168.0.2:8081/repository/maven-releases/</url>
</repository>
</distributionManagement>
🔹 Step 3: Add Group Repository
<repositories>
<repository>
<id>nexus-group</id>
<url>http://192.168.0.2:8081/repository/maven-public/</url>
</repository>
</repositories>
🔹 Step 4: Add Credentials in settings.xml
<servers>
<server>
<id>nexus-snapshot</id>
<username>maven-user</username>
<password>maven</password>
</server>
<server>
<id>nexus-release</id>
<username>maven-user</username>
<password>maven</password>
</server>
<server>
<id>nexus-group</id>
<username>maven-user</username>
<password>maven</password>
</server>
</servers>
🔹 Step 5: Add a Mirror
<mirrors>
<mirror>
<id>nexus-group</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.0.2:8081/repository/maven-public/</url>
</mirror>
</mirrors>
✅ Step 6: Build and Deploy
mvn clean deploy
🔍 What Happens?
Snapshot : 1.0.0-SNAPSHOT -> Mutable. Frequently updated builds.
Release : 1.0.0 -> Immutable. Final production-ready.
📅 Use group repository in <repositories> to avoid defining each individual repo separately. Nexus will aggregate them.
🛰️ Nexus REST API
You can use Nexus's REST API to:
Use tools like curl, Postman, or scripting with auth headers to access endpoints.
🖳️ Cleanup Policies & Scheduled Tasks
♻️ Cleanup Policies
Define rules like:
⏰ Scheduled Tasks