This repository contains a demo project created as part of my DevOps studies in the TechWorld with Nana – DevOps Bootcamp.
https://www.techworld-with-nana.com/devops-bootcamp
Demo Project: Run Nexus on Droplet and Publish Artifact to Nexus
Technologies used: Nexus, DigitalOcean, Linux, Java, Gradle, Maven
Project Description:
- Install and configure Nexus from scratch on a cloud server
- Create new User on Nexus with relevant permissions
- Java Gradle Project: Build Jar & Upload to Nexus
- Java Maven Project: Build Jar & Upload to Nexus
Recommended configuration:
- 8 GB RAM
- 4 CPUs
ssh root@<DROPLET_IP>
apt install openjdk-17-jre-headless net-tools -ycd /opt
wget https://download.sonatype.com/nexus/3/nexus-3.88.0-08-linux-x86_64.tar.gz
tar -zxvf nexus-3.88.0-08-linux-x86_64.tar.gzadduser nexus
chown -R nexus:nexus nexus-3.88.0-08
chown -R nexus:nexus sonatype-work
ls -l # to check if permissions appliedEdit the Nexus startup script:
vim nexus-3.88.0-08/bin/nexusSet:
run_as_user="nexus"su - nexus
/opt/nexus-3.88.0-08/bin/nexus start
ps aux | grep nexus
netstat -lpnt- Open firewall port
8081 - Navigate to:
http://<DROPLET_IP>:8081
Retrieve the initial admin password:
cat /opt/sonatype-work/nexus3/admin.passwordEnable anonymous access during initial setup.
-
Create Nexus Role and User
-
Type:
Nexus role -
Role ID:
nx-java -
Role Name:
nx-java -
Privileges:
nx-repository-view-maven2-*-*
Create Nexus user
- Assign the
nx-javarole
git clone https://gitlab.com/twn-devops-bootcamp/latest/06-nexus/java-appCreate gradle.properties:
repoUser = dev
repoPassword = xxxxxUpdate build.gradle:
plugins {
id 'java'
id 'maven-publish'
}
group = "com.example"
version = "1.0-SNAPSHOT"
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
name = "nexus"
url = uri("http://<DROPLET_IP>:8081/repository/maven-snapshots/")
allowInsecureProtocol = true
credentials {
username = project.findProperty("repoUser")
password = project.findProperty("repoPassword")
}
}
}
}Edit settings.gradle
rootProject.name = 'my-app'gradle build
gradle publish --warning-mode allgit clone https://gitlab.com/twn-devops-bootcamp/latest/06-nexus/java-maven-appUpdate pom.xml under build > plugins:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.4</version>
</plugin>Add below the build section:
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://<DROPLET_IP>:8081/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>Create ~/.m2/settings.xml:
<settings>
<servers>
<server>
<id>nexus-snapshots</id>
<username>dev</username>
<password>xxxxx</password>
</server>
</servers>
</settings>mvn package
mvn deploy







