Skip to content

Nexus (Maven Central, Sonatype, etc)

Dot-Rar edited this page Nov 10, 2018 · 1 revision

Nexus (Maven Central, Sonatype, etc)

DependencyManager provides classes for Maven Central and various other Sonatype repositories that use the Nexus system:

  • MavenCentralDependency
  • SonatypeOSSStagingDependency
  • SonatypeOSSReleasesDependency
  • SonatypeOSSSnapshotDependency

All of these classes have the same constructor:

MavenCentralDependency(Plugin owner, String group, String artifact, String version)

Create an instance of the class that you want, and pass in:

  • The instance of your plugin
  • The artifact's group ID
  • The artifact's artifact ID
  • The artifact's version

As an example, we'll load Toml4J from Maven Central.

Here's the result:

Dependency dependency = new MavenCentralDependency(this, "com.moandjiezana.toml", "toml4j", "0.7.2");

After we have created our Dependency instance, we can load it like normal by using Dependency#load:

dependency.load(() -> { // On complete  
  System.out.println("Artifact has been loaded");  
}, (ex) -> { // On error  
  ex.printStackTrace();  
});

Or as a one-liner:

dependency.load(this::start, Throwable::printStackTrace);```
Clone this wiki locally