Skip to content

Gradle plugin for configuring and uploading artifacts to Sonatype Nexus

License

Notifications You must be signed in to change notification settings

aaronklor/gradle-nexus-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gradle Sonatype Nexus plugin

Sonatype Logo

The plugin provides support for configuring and uploading artifacts to Sonatype Nexus. It can be configured to deploy to a self-hosted instance of Nexus or Sonatype OSS. The default setup is to publish to Sonatype OSS. Currently, Java and Groovy project artifact generation is supported. In addition to the JAR and POM file artifacts containing the JavaDocs and source files are created. Signing the artifacts is optional.

Usage

To use the Sonatype Nexus plugin, include in your build script:

apply plugin: 'nexus'

The plugin JAR needs to be defined in the classpath of your build script. It is directly available on Maven Central. Alternatively, you can download it from GitHub and deploy it to your local repository. The following code snippet shows an example on how to retrieve it from Maven Central:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.2'
    }
}

Tasks

The Nexus plugin defines two tasks:

  • javadocJar: Compiles the javadoc and creates a jar from it.
  • sourcesJar: Creates a jar containing the sources of the main source set.

The output of both are added to the archives configuration.

Additionally, it applies the Maven plugin plugin as well as signing in order to leverage maven's install and uploadArchives tasks.

Convention properties

The Nexus plugin defines the following convention properties in the nexus closure:

  • sign: Specifies whether to sign the artifacts using the signing plugin (defaults to true).
  • repositoryUrl: The stable release repository URL (defaults to https://oss.sonatype.org/service/local/staging/deploy/maven2/).
  • snapshotRepositoryUrl: The stable release repository URL (defaults to https://oss.sonatype.org/content/repositories/snapshots/).

Additional configuration

In addition to the convention properties the automatically generated POM file can be modified. To provide the data for the POM generation specify the information within the configuration element modifyPom.project.

modifyPom {
    project {
        ...
    }
}

In your ~/.gradle/gradle.properties you will need to set the mandatory Nexus credentials required for uploading your artifacts.

nexusUsername = yourUsername
nexusPassword = yourPassword

Example

modifyPom {
    project {
        name 'Gradle Sonatype Nexus plugin'
        description 'Gradle plugin that provides tasks for configuring and uploading artifacts to Sonatype Nexus.'
        url 'https://github.com/bmuschko/gradle-nexus-plugin'
        inceptionYear '2012'

        scm {
            url 'https://github.com/bmuschko/gradle-nexus-plugin'
            connection 'scm:https://bmuschko@github.com/bmuschko/gradle-nexus-plugin.git'
            developerConnection 'scm:git://github.com/bmuschko/gradle-nexus-plugin.git'
        }

        licenses {
            license {
                name 'The Apache Software License, Version 2.0'
                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                distribution 'repo'
            }
        }

        developers {
            developer {
                id 'bmuschko'
                name 'Benjamin Muschko'
                email 'benjamin.muschko@gmail.com'
            }
        }
    }
}

nexus {
    sign = true
    repositoryUrl = 'http://localhost:8081/nexus/content/repositories/internal/'
    snapshotRepositoryUrl = 'http://localhost:8081/nexus/content/repositories/internal-snapshots/'
}

FAQ

How do I publish my artifacts to Maven Central aka Sonatype OSS?

By default the plugin is configured to upload your artifacts to the release and snapshot repository URLs of Sonatype OSS. There's no additional configuration required. If you want to tweak the automatically generated POM file please you the modifyPom closure. Make sure to stick to the process described in the Sonatype OSS Maven Repository usage guide.

About

Gradle plugin for configuring and uploading artifacts to Sonatype Nexus

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Groovy 64.8%
  • Shell 35.2%