Skip to main content

Nexus API Wrapper

The Nexus API Wrapper is a small Java client for the REST API of Sonatype Nexus Repository 3. It covers the parts you need to find and fetch artifacts:

  • search for components and assets, with all common search parameters,
  • read, list, download and delete assets,
  • list repositories.

Every request can run blocking on your thread or asynchronous with a CompletableFuture. Requests share a rate limit, so a loop over many pages does not flood your Nexus.

It does not cover the admin parts of the API, like creating repositories, users, roles or tasks.

Requirements​

WhatVersion
Java21 or newer. The library is compiled for Java 21 and ships a module descriptor (de.chojo.nexus).
Nexus Repository3, with the REST API under /service/rest/v1. Checked against 3.96.1 Community.
Jackson3 (tools.jackson). The library brings jackson-databind with it.
SLF4JThe library logs through slf4j-api and brings it. Add an SLF4J binding to see the log output.

Add the dependency​

The library is published to EldoNexus.

repositories {
maven("https://eldonexus.de/repository/maven-public/")
}

dependencies {
implementation("de.chojo:nexus-api-wrapper:2.0.0")
}

Snapshots of the next version are in https://eldonexus.de/repository/maven-snapshots/.

Quick start​

Find the newest jar of an artifact and download it:

NexusRest nexus = NexusRest.defaultApi("eldonexus.de");

PageAssetXO page = nexus.v1().search().assets().search()
.repository("maven-releases")
.mavenGroupId("de.chojo")
.mavenArtifactId("nexus-api-wrapper")
.mavenExtension("jar")
.sort(Sort.VERSION)
.direction(Direction.DESC)
.complete();

AssetXO newest = page.items().getFirst();
byte[] jar = newest.download().complete();

Where to go next​

  • Client: create the client, log in, tune the HTTP client and the threads.
  • Requests: blocking and asynchronous calls, errors and the rate limit.
  • Search: search components and assets, page through results.
  • Assets: read, list, download and delete assets.
  • Repositories: list the repositories of a Nexus.
  • Entities: the objects you get back.
  • Upgrading to 2.0: what changed since 1.0.5.