Getting started with the Nexus Maven repository manager - OS |Video upload date:  · Duration: PT6M26S  · Language: EN

Quick tutorial on setting up Nexus Repository Manager OSS version 2 for Maven repos Learn to install start configure and deploy artifacts

Quick overview

If your team treats the public Maven Central like a sketchy buffet then you need a repository manager. Nexus OSS is the no-nonsense repository manager that hosts your private Maven artifacts and proxies remote Maven repositories for CI and local development. This guide walks through a pragmatic setup so you can stop wrestling with dependency hell and start blaming cache policies instead.

Before you start

  • Java installed and working. Run java -version and try not to cry if the JVM is ancient.
  • Download the Nexus OSS archive from Sonatype or a trusted mirror.
  • A non root user for running Nexus, because running services as root is a great way to write horror stories.

Install and start Nexus Repository Manager

Unpack the distribution into the directory you intend to run Nexus from and set ownership so the Nexus user can actually read and write files.

tar xvf sonatype-nexus-oss-2.x.y-bundle.tar.gz
sudo chown -R nexus:nexus sonatype-nexus-oss-2.x.y

Start the server with the bundled script and tail the log to watch startup messages.

sudo -u nexus ./bin/nexus start
tail -f sonatype-work/nexus/logs/nexus.log

The default HTTP port is 8081 unless you or that ancient sysadmin changed it. Note the port so Maven and CI can reach Nexus.

Access the web UI and secure the admin account

Open the Nexus web console in your browser at the host and port from the previous step. Log in with the default admin credentials documented for your Nexus version and immediately change the password. The web UI is where you create repositories, manage users, and break fewer things than you would via config files alone.

Create hosted, proxy and group Maven repositories

Minimal setup for a typical Maven workflow includes:

  • A hosted repository for internal artifacts and CI deployments
  • A proxy repository that points at Maven Central, typically using the URL https://repo1.maven.org/maven2
  • An optional group repository to present a single endpoint to Maven clients

Give repo names that humans and scripts can live with long term. Avoid whimsical names unless you enjoy painful rename migrations later.

Repository tips

  • Use semantic naming like maven-releases and maven-snapshots
  • Limit anonymous access unless you want the whole internet to see your artifact hoard
  • Set proxy cache timeouts according to your network and build reliability needs

Configure Maven to use Nexus

Edit your Maven settings.xml to add credentials for deploys and a mirror so normal Maven requests go to your Nexus endpoint. Update your projects to point distributionManagement at the hosted repo when you publish artifacts.

Example snippet to add to ~/.m2/settings.xml:

<settings>
  <servers>
    <server>
      <id>nexus-repo</id>
      <username>deploy_user</username>
      <password>password_here</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>nexus-mirror</id>
      <mirrorOf>central

If your security policy is picky then use Maven's password encryption with the settings security file. That's the grown up way to avoid the stickynote on the monitor approach.

Deploy and verify artifacts

Update your POM with the distributionManagement coordinates for the hosted repository and run the usual Maven choreography to publish.

mvn deploy
mvn dependency:get -Dartifact=groupId:artifactId:version

Use mvn dependency:get for quick checks that Nexus is serving the artifact you just pushed. CI pipelines should be configured to authenticate to Nexus for deploy steps and to use the group repo for resolving dependencies.

Housekeeping and artifact management

Snapshots pile up like bad decisions. Configure snapshot cleanup policies and retention rules in Nexus so your disk does not become a shrine to old builds. Set retention rules for both snapshots and releases according to your release cadence and storage budget.

  • Automate cleanup of old snapshots
  • Enable content validation to avoid corrupted artifacts spreading to builds
  • Monitor cache hit ratios to tune proxy settings and save bandwidth

Wrapping up

Setting up Nexus OSS as your Maven repository manager gives DevOps teams a controlled artifact management solution for local development and CI. You get hosting, proxying and grouping of Maven repositories along with access controls and retention policies. It is not magic but it is reliable. Document your repo names credentials and policies so future you does not open a ticket that tries to explain this to past you.

If you run into trouble check the Nexus logs, consult Sonatype documentation for your specific Nexus OSS version, and remember that most problems are either permissions or typos. Prefer the former to avoid blaming typos forever.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.