All Projects → gradle-nexus → publish-plugin

gradle-nexus / publish-plugin

Licence: Apache-2.0 license
Gradle plugin for publishing to Nexus repositories

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to publish-plugin

nexus-oss-on-aws
Deploy Sonatype Nexus Repository OSS on AWS with well architecture.
Stars: ✭ 51 (-79.01%)
Mutual labels:  nexus-repository-manager
aletheia-admin
Project documentation including our README, contributing guidelines and more.
Stars: ✭ 32 (-86.83%)
Mutual labels:  publishing
plostime
Publication delays at PLOS and 3,475 other journals
Stars: ✭ 19 (-92.18%)
Mutual labels:  publishing
Alto
A clean, minimalist theme featuring a light and dark mode for Ghost
Stars: ✭ 109 (-55.14%)
Mutual labels:  publishing
alice-docs
A simple and quick publishing framework utilizing Google Docs
Stars: ✭ 14 (-94.24%)
Mutual labels:  publishing
pandoc-templates
An opinionated set of Pandoc templates and scripts for converting markdown to DOCX manuscripts that adhere to William Shunn's Proper Manuscript Format guidelines using Pandoc.
Stars: ✭ 30 (-87.65%)
Mutual labels:  publishing
quantum-journal
LaTeX template class for Quantum - the open journal for quantum science
Stars: ✭ 73 (-69.96%)
Mutual labels:  publishing
Github-Release-Action
Publish Github releases in an action
Stars: ✭ 100 (-58.85%)
Mutual labels:  publishing
Edition
The newsletter theme for Ghost
Stars: ✭ 60 (-75.31%)
Mutual labels:  publishing
css-print
CSS Print
Stars: ✭ 23 (-90.53%)
Mutual labels:  publishing
thunder-distribution
A Drupal-based platform for professional publishers
Stars: ✭ 31 (-87.24%)
Mutual labels:  publishing
Prometheus
🌈 A Clean And Modern Ghost Theme with Progressive Web Apps (PWA)
Stars: ✭ 94 (-61.32%)
Mutual labels:  publishing
RepSeP
Reproducible Self-Publishing - Demo Publications in the Most Common Formats
Stars: ✭ 14 (-94.24%)
Mutual labels:  publishing
Edge
A visually aesthetic portfolio theme for Ghost
Stars: ✭ 61 (-74.9%)
Mutual labels:  publishing
web-verse
Toolbox for deep, resilient, markup-invariant linking into HTML documents without their cooperation
Stars: ✭ 25 (-89.71%)
Mutual labels:  publishing
authorship
A modern approach to author attribution in WordPress.
Stars: ✭ 39 (-83.95%)
Mutual labels:  publishing
in2publish core
in2publish Community Version
Stars: ✭ 38 (-84.36%)
Mutual labels:  publishing
apple-news
A Node.js client for interacting with the Apple News API 📰
Stars: ✭ 34 (-86.01%)
Mutual labels:  publishing
com.elovirta.ooxml
DITA to Word plug-in
Stars: ✭ 19 (-92.18%)
Mutual labels:  publishing
languagecheck
Improve the language of your paper before submission
Stars: ✭ 72 (-70.37%)
Mutual labels:  publishing

Gradle Nexus Publish Plugin

CI Status Gradle Plugin Portal

This Gradle plugin is a turn-key solution for publishing to Nexus. You can use it to publish your artifacts to any Nexus instance (internal or public). It is great for publishing your open source to Sonatype, and then to Maven Central, in a fully automated fashion.

Vanilla Gradle is great but it cannot fully automate publications to Nexus. This plugin enables isolation of staging repositories so that you can reliably publish from CI, and each publication uses a brand new, explicitly created staging repo (more). Moreover, the plugin provides tasks to close and release staging repositories, covering the whole releasing process to Maven Central.

This plugin is intended as a replacement of the Gradle Nexus Staging Plugin and Nexus Publish Plugin duo. See a dedicated migration guide.

Usage

Applying the plugin

The plugin must be applied to the root project and requires Gradle 5.0 or later. It is important to set the group and the version to the root project, so the plugin can detect if it is a snapshot version or not in order to select the correct repository where artifacts will be published.

plugins {
    id("io.github.gradle-nexus.publish-plugin") version "«version»"
}

group = "com.example.library"
version = "1.0.0"

Publishing to Maven Central via Sonatype OSSRH

In order to publish to Maven Central (aka the Central Repository or just Central) via Sonatype's OSSRH Nexus, you simply need to add the sonatype() repository like in the example below. Its nexusUrl and snapshotRepositoryUrl values are pre-configured.

nexusPublishing {
    repositories {
        sonatype()
    }
}

Important. Users registered in Sonatype after 24 February 2021 need to customize the following URLs:

nexusPublishing {
    repositories {
        sonatype {  //only for users registered in Sonatype after 24 Feb 2021
            nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
            snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
        }
    }
}

(if unsure check the server address in a corresponding ticket for your project in Sonatype's Jira)

In addition, for both groups of users, you need to set your Nexus credentials. To increase security, it is advised to use the user token's username and password pair (instead of regular username and password). Those values should be set as the sonatypeUsername and sonatypePassword project properties, e.g. in ~/.gradle/gradle.properties or via the ORG_GRADLE_PROJECT_sonatypeUsername and ORG_GRADLE_PROJECT_sonatypePassword environment variables.

Alternatively, you can configure credentials in the sonatype block:

nexusPublishing {
    repositories {
        sonatype {
            username = "your-user-token-username"
            password = "your-user-token-password"
        }
    }
}

Finally, call publishToSonatype closeAndReleaseSonatypeStagingRepository to publish all publications to Sonatype's OSSRH Nexus and subsequently close and release the corresponding staging repository, effectively making the artifacts available in Maven Central (usually after a few minutes).

Note that until #19 is done, the publishToSonatype closeAndReleaseSonatypeStagingRepository tasks have to be executed in the same Gradle invocation because closeAndRelease relies on information that is not persisted between calls to Gradle. Failing to do so will result in an error like No staging repository with name sonatype created.

Please bear in mind that - especially on the initial project publishing to Maven Central - it might be wise to call just publishToSonatype closeSonatypeStagingRepository and manually verify that the artifacts placed in the closed staging repository in Nexus looks ok. After that, the staging repository might be dropped (if needed) or manually released from the Nexus UI.

Full example

Groovy DSL

plugins {
    id "java-library"
    id "maven-publish"
    id "io.github.gradle-nexus.publish-plugin" version "«version»"
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from(components.java)
        }
    }
}

nexusPublishing {
    repositories {
        myNexus {
            nexusUrl = uri("https://your-server.com/staging")
            snapshotRepositoryUrl = uri("https://your-server.com/snapshots")
            username = "your-username" // defaults to project.properties["myNexusUsername"]
            password = "your-password" // defaults to project.properties["myNexusPassword"]
        }
    }
}

Kotlin DSL

plugins {
    `java-library`
    `maven-publish`
    id("io.github.gradle-nexus.publish-plugin") version "«version»"
}

publishing {
    publications {
        create<MavenPublication>("mavenJava") {
            from(components["java"])
        }
    }
}

nexusPublishing {
    repositories {
        create("myNexus") {
            nexusUrl.set(uri("https://your-server.com/staging"))
            snapshotRepositoryUrl.set(uri("https://your-server.com/snapshots"))
            username.set("your-username") // defaults to project.properties["myNexusUsername"]
            password.set("your-password") // defaults to project.properties["myNexusPassword"]
        }
    }
}

HTTP Timeouts

You can configure the connectTimeout and clientTimeout properties on the nexusPublishing extension to set the connect and read/write timeouts (both default to 5 minutes). Good luck!

Retries for state transitions

When closing or releasing a staging repository the plugin first initiates the transition and then retries a configurable number of times with a configurable delay after each attempt. Both can be configured like this:

Groovy DSL

import java.time.Duration

nexusPublishing {
    transitionCheckOptions {
        maxRetries = 100
        delayBetween = Duration.ofSeconds(5)
    }
}

Kotlin DSL

import java.time.Duration

nexusPublishing {
    transitionCheckOptions {
        maxRetries.set(100)
        delayBetween.set(Duration.ofSeconds(5))
    }
}
  • maxRetries default value is 60.
  • delayBetween default value is 10 seconds.

Behind the scenes

The plugin does the following:

  • configure a Maven artifact repository for each repository defined in the nexusPublishing { repositories { ... } } block in each subproject that applies the maven-publish plugin
  • creates a retrieve{repository.name.capitalize()}StagingProfile task that retrieves the staging profile id from the remote Nexus repository. This is a diagnostic task to enable setting the configuration property stagingProfileId in nexusPublishing { repositories { myRepository { ... } } }. Specifying the configuration property rather than relying on the API call is considered a performance optimization.
  • create a initialize${repository.name.capitalize()}StagingRepository task that starts a new staging repository in case the project's version does not end with -SNAPSHOT (customizable via the useStaging property) and sets the URL of the corresponding Maven artifact repository accordingly. In case of a multi-project build, all subprojects with the same nexusUrl will use the same staging repository.
  • make all publishing tasks for each configured repository depend on the initialize${repository.name.capitalize()}StagingRepository task
  • create a publishTo${repository.name.capitalize()} lifecycle task that depends on all publishing tasks for the corresponding Maven artifact repository
  • create close${repository.name.capitalize()}StagingRepository and release${repository.name.capitalize()}StagingRepository tasks that must run after the all publishing tasks
    • to simplify the common use case also a closeAndRelease${repository.name.capitalize()}StagingRepository task is created which depends on all the close* and release* tasks for a given repository

Historical background

In 2015, Marcin Zajączkowski created gradle-nexus-staging-plugin which was providing an ability to close and release staging repositories in Nexus repository manager. It opened an opportunity to manage releasing Gradle projects to Maven Central completely from code. Over the years, it has been adopted by various projects across the globe, however there was a small problem. Due to technical limitations in the publishing process in Gradle, it was required to use heuristics to track implicitly created staging repositories, what often failed for multiple repositories in a given state. The situation became even worse when Travis changed its network architecture in late 2019 and the majority of releases started to fail. Here, Marc Philipp entered the stage who created Nexus Publish Plugin which was enriching the publishing mechanism in Gradle to explicitly create staging repositories and publish (upload) artifacts directly to it.

Those two plugins nicely worked together, providing a reliable way to handle publishing artifacts to Maven Central (and to other Nexus instances in general). However, the need of using two plugins was very often confusing for users. As a result, an idea to create one plugin mixing the aforementioned capabilities emerged. It materialized in 2020/2021 as Gradle Nexus Publish Plugin, an effect of combined work of Marc and Marcin, supported by a pack of contributors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].