Skip to content

Princeton45/nexus-droplet-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Running Nexus on Droplet and Publishing Artifact to Nexus

In this project, I will be setting up a Nexus repository on a DigitalOcean server. Then, I will publish Java artifacts to it using Gradle and Maven build tools.

Nexus Diagram

Technologies

  • Nexus Repository Manager
  • DigitalOcean
  • Linux (Ubuntu)
  • Java
  • Gradle
  • Maven

Step-by-Step Adventure

1. Setting Up My DigitalOcean Droplet

First things first, I needed a server. I went to DigitalOcean and spun up a new Droplet. I chose Ubuntu as the OS because it's familiar and well-supported.

Droplet

Once the Droplet was live, I SSH'd into it using my terminal.

Droplet

2. Installing and Configuring Nexus

With my server ready, it was time to bring in Nexus. I followed the official Nexus installation guide. Here's the gist:

  1. Download Nexus: I grabbed the latest version from the Sonatype website.

    https://help.sonatype.com/en/download.html

  2. Extract & Run: Unpacked the downloaded file and ran the Nexus startup script. I am going to extract the contents in the /opt folder.

    cd /opt
    wget https://download.sonatype.com/nexus/3/nexus-3.76.1-01-unix.tar.gz 
    tar -zxvf nexus-3.76.1-01-unix.tar.gz
  3. Nexus Service Account: I then created a nexus service account called nexus-princeton on the Linux server and made the service account an owner of the nexus and sonatype directory

serviceacc

  1. Setting Nexus Configuration: Next I set the nexus-3.76.1-01/bin/nexus.rc configuration file so that it will run as a nexus user.

runas

  1. Starting Nexus service: I ran the command below to start the nexus service.

/opt/nexus-3.76.1-01/bin/nexus start

nexusrunning

  1. Access Nexus: Once Nexus was up, I opened my web browser and navigated to http:http://159.223.109.89//:8081.

access-nexus

3. Java Gradle Project: Build and Upload

Now for the fun part – getting my Java project artifacts into Nexus. I started with a simple Gradle project.

  1. Creating Nexus user: In this step, I need to create a Nexus user in the Nexus application because when connecting Gradle and Maven to Nexus, we don't want to use the default admin credentials.

The Nexus user will only have permissions to upload artifact files to particular Nexus repositories.

I created a custom nx-java role with the required permissions.

role

  1. Configuring Maven Gradle to connect to Nexus: In this step, I need to configure Gradle to connect to Nexus via the Nexus Repo URL & Credentials

  2. Create a Simple Project: I created a basic Java project with a build.gradle file.

    • Picture Suggestion: A screenshot of your project directory structure and/or your simple Java code.
      • Caption: "My humble Java project, ready to be built and shared."
  3. Configure build.gradle: I added the maven-publish plugin to my build.gradle and configured it to publish to my Nexus repository.

    plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.0-SNAPSHOT'
    id 'io.spring.dependency-management' version '1.1.0'
}

group 'com.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 17

apply plugin: 'maven-publish'

publishing {
    publications {
        maven(MavenPublication) {
            artifact("build/libs/my-app-$version"+".jar"){
                extension 'jar'
            }
        }
    }

    repositories {
        maven {
            name 'nexus'
            url "http://159.223.109.89:8081/repository/maven-snapshots/" 
            allowInsecureProtocol = true
            credentials {
                username project.repoUser
                password project.repoPassword
            }
        }
    }
}
  1. Build and Publish: I ran the following Gradle commands:

    gradle build
    gradlew publish

gradle-publish

  1. Verify in Nexus: I went back to my Nexus UI, browsed the repositories, and there it was, in the maven-snapshots repository just as specified.

gradle-repo

4. Java Maven Project: Build and Upload

The process for Maven is quite similar.

  1. Create a Simple Project: I set up a basic Java project with a pom.xml file.

  2. Configure pom.xml: I added the distributionManagement section to my pom.xml to point to my Nexus repository. Again, replace the placeholders.

    <project>
        ...
        <distributionManagement>
            <repository>
                <id>nexus-releases</id>
                <url>http://<your_droplet_ip>:8081/repository/maven-releases/</url>
            </repository>
        </distributionManagement>
        ...
    </project>
  3. Configure settings.xml: I added my Nexus credentials to my Maven settings.xml file (usually found in ~/.m2/). This is crucial to avoid putting credentials in every project.

    <settings> 
    <servers>
        <server>
            <id>nexus-snapshots</id>
            <username><your_nexus_username></username>
            <password><your_nexus_password></password>
        </server>
    </servers>
    </settings> 
  4. Build and Deploy: I used the following Maven commands:

    mvn package
    mvn deploy

maven-deploy

  1. Verify in Nexus: Just like with Gradle, I checked Nexus and found my Maven-built artifact happily residing in the repository.

maven-nexus

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published