Writing Scripts

The scripting language used on the repository manager is Groovy. Any editor can be used to author the scripts.

The available APIs are contained in a number of JAR files. All these files, including JavaDoc and Sources archives, are available from the Central Repository. They can be manually downloaded and extracted. E.g. the different versions and the specific JAR files for org.sonatype.nexus:nexus-core are available in versioned directories at http://repo1.maven.org/maven2/org/sonatype/nexus/nexus-core/.

This manual process can be simplified and improved by the usage of a Maven project declaring the relevant components as dependencies. An example project with this setup called nexus-script-example and a few scripts are available in the example project.

Maven Project pom.xml Declaring the API Dependencies for Scripting

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

Development environments such as IntelliJ IDEA or Eclipse IDE can download the relevant JavaDoc and Sources JAR files to ease your development. Typically you would create your scripts in src/main/groovy or src/main/scripts

The scripting API exposes specific tooling for IntelliJ IDEA that allows you to get access to code completion and similar convenience features, while writing your scripts in this Maven project. Currently the API exposes four main providers with numerous convenient methods:

  • core
  • repository
  • blobStore
  • security

The API is deliberately designed to be simple to use. It encapsulates complex configuration in single method invocations. Many of the included methods use default values that can be omitted. For example, the method to create a hosted repository using the Maven format in the simplest usage simply requires a name.


This method simply uses the default values for the rest of the parameters and is therefore equivalent to:

repository.createMavenHosted("private", BlobStoreManager.DEFAULT_BLOBSTORE_NAME, VersionPolicy.RELEASE, WritePolicy.ALLOW_ONCE, LayoutPolicy.STRICT)

You can inspect the default values in the API documentation available by inspecting the declaration of the specific methods in your IDE or by viewing the JavaDoc.

In terms of overall complexity of the scripts created, it is best to break large tasks up into multiple scripts and therefore invocations.