Gradle Plugin for publishing artifacts to Sonatype and Nexus

Overview

Introduction

Due to Sonatype's strict validation rules, the publishing requirement must be satisfied by every artifact which wants to be published to Sonatype.

For Java and Android library projects, the publishing configurations are very similar, but the configurations of creating publication are quite different, this gradle plugin is used to simplify the engineering complexity of publishing artifacts to Sonatype, developers don't need to write boilerplate publishing DSL for each project to satisfy Sonatype validation rules.

This plugin not only support publishing artifacts to Sonatype, but also support publishing artifacts to private Nexus repository.

Prerequisite

For more information, see References

Getting Started

Apply plugin

Plugins DSL

plugins {
    id("io.johnsonlee.sonatype-publish-plugin") version "1.2.0"
}

group = "..."
version = "..."

Legacy DSL

buildscript {
    repositories {
        mavenCentral()
        google()
        gradlePluginPortal()
    }
    dependencies {
        classpath("io.johnsonlee:sonatype-publish-plugin:1.2.0")
    }
}

apply plugin: "io.johnsonlee.sonatype-publish-plugin"

group = "..."
version = "..."

Configure env and properties

Sonatype

  • OSSRH_USERNAME

    The account id of Sonatype, searching from project properties by default, otherwise searching from system env

  • OSSRH_PASSWORD

    the account password of Sonatype, searching from project properties by default, otherwise searching from system env

  • OSSRH_PACKAGE_GROUP

    The package group of Sonatype, e.g. io.johnsonlee, searching from project properties by default, otherwise searching from system env

Nexus

  • NEXUS_URL

    The endpoint of Nexus service, e.g. http://nexus.johnsonlee.io/, searching from project properties by default, otherwise searching from system env

  • NEXUS_USERNAME

    The account id of Nexus, searching from project properties by default, otherwise searching from system env

  • NEXUS_PASSWORD

    The account password of Nexus, searching from project properties by default, otherwise searching from system env

Signing

  • signing.keyId

    The GPG key id (short format). In this example, the GPG key id is 71567BD2

    $ gpg --list-secret-keys --keyid-format=short
    /Users/johnsonlee/.gnupg/secring.gpg
    ------------------------------------
    sec   4096R/71567BD2 2021-03-10 [expires: 2031-03-10]
    uid                  Johnson
    ssb   4096R/4BA89E7A 2021-03-10
    
  • signing.password

    The password of GPG key

  • signing.secretKeyRingFile

    The secret key ring file, e.g. /Users/johnsonlee/.gnupg/secring.gpg

    The best practice is putting the properties above into ~/.gradle/gradle.properties

    OSSRH_USERNAME=johnsonlee
    OSSRH_PASSWORD=*********
    OSSRH_PACKAGE_GROUP=io.johnsonlee
    signing.keyId=71567BD2
    signing.password=*********
    signing.secretKeyRingFile=/Users/johnsonlee/.gnupg/secring.gpg

Configure Git Repository

The following git configurations are be used for generating maven POM file, please skip if already done.

  • user.name

    git config user.name <username>
  • user.email

    git config user.email <email-address>
  • remote.origin.url (optional)

    The remote.origin.url is available by default unless the git repository is created locally

    git remote add origin [email protected]:<username>/<repository>

Configure Project Info

  • project.group

    The groupId of the publication, only the root project need to configured, subproejcts will inherit from the root project

  • project.version

    The version of the publication, only the root project need to configured, subproejcts will inherit from the root project

The artifactId of the publication is the project.name by default

Configure License (optional)

Add a license file (LICENSE, LICENSE.txt, LICENSE.md or LICENSE.rst) into project, then the license type will be recognized automatically.

For more information on repository licenses, see "Supported Licenses"

Publish Artifacts to Sonatype

./gradlew clean publishToSonatype
./gradlew closeAndReleaseRepository

Publish Artifacts to Nexus

./gradlew clean publish

After release complete, the artifacts will be synced to Maven Central automatically

References

You might also like...
Klinker is a gradle plugin making it possible to link kotlin native executables with custom linkers and options.

Klinker is a gradle plugin making it possible to link kotlin native executables with custom linkers and options. It does this by creating a static library for kotlin compilation, then generates a c+kotlin wrapper that calls into kotlin to start the app, finally using the specified compiler to compile and link the c code and kotlin library into a binary.

Gradle plugin to check, if rest-controllers are used by clients and clients have suitable rest-interfaces

Verify-Feign Gradle Plugin This plugin will help you to verify all rest-clients and -controllers in a multimodule spring project. It will check, if al

The core Gradle plugin and associated logic used for Slack's Android app

slack-gradle-plugin This repository contains the core Gradle plugin and associated logic used for Slack's Android app. This repo is effectively read-o

Kmp4free - A Gradle Plugin that allows seamless switching between Kotlin JVM and the Kotlin Multiplatform Plugins
Kmp4free - A Gradle Plugin that allows seamless switching between Kotlin JVM and the Kotlin Multiplatform Plugins

🆓 kmp4free Allows you to toggle between Kotlin JVM Plugin - Kotlin Multiplatform with a Gradle Property kmp4free=true. This Gradle Plugin was built

A simple gradle plugin that lets you create a download asset from zeplin and convert them to vector drawables automatically
A simple gradle plugin that lets you create a download asset from zeplin and convert them to vector drawables automatically

A simple gradle plugin that lets you create a download asset from zeplin and convert them to vector drawables automatically elephant project using 100% Kotlin and be up and running in a few seconds.

A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs.

A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs.

Grazel is a Gradle plugin to automate generation of valid Bazel files for a given Android/Kotlin/Java project.

Grazel Grazel stands for Gradle to Bazel. It is a Gradle plugin that enables you to migrate Android projects to Bazel build system in an incremental a

 Gradle Plugin for Continuous Integration of AppSweep App Testing.
Gradle Plugin for Continuous Integration of AppSweep App Testing.

This Gradle plugin can be used to continuously integrate app scanning using AppSweep into your Android app build process

Gradle plugin which validates the licenses of your dependency graph match what you expect

Gradle plugin which validates the licenses of your dependency graph match what you expect

Comments
  • Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.

    Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.

    after build project:

    An exception occurred applying plugin request [id: 'io.johnsonlee.sonatype-publish-plugin', version: '1.7.0']
    > Failed to apply plugin 'io.codearte.nexus-staging'.
       > Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.
    
    • AGP : 7.2.2
    opened by lwj1994 5
  • java.lang.IllegalStateException: Could not create domain object 'mavenJava' (MavenPublication)

    java.lang.IllegalStateException: Could not create domain object 'mavenJava' (MavenPublication)

    Caused by: org.gradle.internal.typeconvention.UnsupportedNotationException: Cannot convert the provided notation to an object of type MavenArtifact: task ':plugin:packageJavadocForMavenJava'. The following types/formats are supports:

    • Instances of MavenArtifact.
    • Instances of AbstractArchiveTask, for example jar.
    • Instances of PublishArtifact.
    • Maps containing a 'source' entry, for example [source: '/path/to/file', extension: 'zip'].
    • Anything that can be converted to a file, as per Project.file()
    opened by johnsonlee 0
Releases(v1.8.0)
  • v1.8.0(Oct 15, 2022)

    What's Changed

    • Fix issue #9 : Cannot run Project.afterEvaluate(Closure) when the project is already evaluated by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/10

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.7.0...v1.8.0

    Source code(tar.gz)
    Source code(zip)
  • v1.7.0(Jun 5, 2022)

    What's Changed

    • Fix issues in composite build by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/8

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.6.2...v1.7.0

    Source code(tar.gz)
    Source code(zip)
  • v1.6.2(May 28, 2022)

    What's Changed

    • Fix missing dependencies for Kotlin library javadoc packaging by @johnsonlee

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.6.1...v1.6.2

    Source code(tar.gz)
    Source code(zip)
  • v1.6.1(May 18, 2022)

    What's Changed

    • Fix issue #5 caused by incompatible Gradle API by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/7

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.5.6...v1.6.1

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Apr 7, 2022)

    What's Changed

    • Fix license recognition issue

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.3.0...v1.4.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Oct 7, 2021)

    What's Changed

    • Fix InvalidUserDataException: You must specify a URL for a Maven repository by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/3
    • Support publishing artifacts to private Nexus by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/3
    • Fix javadoc task error caused by Android library by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/3

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.2.0...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Oct 6, 2021)

    What's Changed

    • Improve maven pom generation by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/2

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Oct 6, 2021)

    What's Changed

    • Improve publishing configuration by @johnsonlee in https://github.com/johnsonlee/sonatype-publish-plugin/pull/1

    New Contributors

    • @johnsonlee made their first contribution in https://github.com/johnsonlee/sonatype-publish-plugin/pull/1

    Full Changelog: https://github.com/johnsonlee/sonatype-publish-plugin/compare/v1.0.0...v1.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
Johnson Lee
Full Stack Engineer, focus on Android application architecture, mobile infrastructure, my personal blog 👉https://johnsonlee.io
Johnson Lee
Gradle plugin to ease Kotlin IR plugin development and usage in multimodule gradle projects

Gradle plugin to ease Kotlin IR plugin development and usage in multimodule gradle projects. Former: kotlin-ir-plugin-adapter-gradle

null 2 Mar 8, 2022
A Gradle plugin that generates plugin.yml for Bukkit/BungeeCord/Nukkit plugins based on the Gradle project

plugin-yml is a simple Gradle plugin that generates the plugin.yml plugin description file for Bukkit plugins, bungee.yml for Bungee plugins or nukkit.yml for Nukkit plugins based on the Gradle project. Various properties are set automatically (e.g. project name, version or description) and additional properties can be added using a simple DSL.

Plexus 0 Apr 10, 2022
Gradle Plugin to automatically upgrade your gradle project dependencies and send a GitHub pull request with the changes

Gradle Plugin to automatically upgrade your gradle project dependencies and send a GitHub pull request with the changes

Dipien 142 Dec 29, 2022
Gradle Plugin that allows you to decompile bytecode compiled with Jetpack Compose Compiler Plugin into Java and check it

decomposer Gradle Plugin that allows you to decompile bytecode compiled with Jetpack Compose Compiler Plugin into Java and check it How to use Run bui

Takahiro Menju 56 Nov 18, 2022
Gradle Plugin to enable auto-completion and symbol resolution for all Kotlin/Native platforms.

CompleteKotlin Gradle Plugin to enable auto-completion and symbol resolution for all Kotlin/Native platforms. What this plugin provides This zero-conf

Louis CAD 235 Jan 3, 2023
A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes.

Change Tracker Plugin A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes

Ismael Di Vita 110 Dec 19, 2022
Android Gradle Plugin -- Auto Check big image and compress image in building.

McImage I will continue to update, please rest assured to use 中文文档 Android优雅的打包时自动化获取全部res资源 McImage is a Non-invasive plugin for compress all res in

smallSohoSolo 1.1k Dec 28, 2022
Gradle plugin that generates a Swift Package Manager manifest and an XCFramework to distribute a Kotlin Multiplatform library for Apple platforms.

Multiplatform Swift Package This is a Gradle plugin for Kotlin Multiplatform projects that generates an XCFramework for your native Apple targets and

Georg Dresler 262 Jan 5, 2023
Gradle plugin that parses version updates and assigns them to groups of people.

Notifier Gradle Plugin This gradle plugin serves the need of automating how dependencies are handles in a project. More specifically, it functions usi

Plum 4 Oct 27, 2022
A Gradle plugin enforcing pre-commit and commit-msg Git hooks configuration

A Gradle plugin enforcing pre-commit and commit-msg Git hooks configuration. Conventional-commits-ready.

Danilo Pianini 24 Dec 16, 2022