Skip to content

Latest commit

 

History

History
77 lines (63 loc) · 2.6 KB

README.md

File metadata and controls

77 lines (63 loc) · 2.6 KB

Read this in other languages: English, 中文.

Maven Central Portal publish plugin (new publish process)

According to Sonatype, the Central Portal will replace the legacy OSSRH service for publishing. However, there is currently no official Gradle plugin to do this. This project is based on Gradle built-in plugin to implement it. The general idea is to use Gradle's built-in "maven-publish" plugin to publish the package to the local repository, then package the resources in the local repository into a bundle, and finally upload it to the Maven Central Portal.

To use the plugin, just add the following to the build.gradle file:

plugins {
    id 'maven-publish'
    id 'signing'
    // The Central Portal publish plugin
    id 'tech.yanand.maven-central-publish' version 'x.y.z'
}

java {
    // Sonatype officially requires Java source and Java doc
    withJavadocJar()
    withSourcesJar()
}

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

            pom {
                // Please define according to Sonatype official requirements
            }
        }
    }

    repositories {
        maven {
            name = "Local"
            url = layout.buildDirectory.dir('repos/bundles')
        }
    }
}

signing {
    // About GPG signing, please refer to https://central.sonatype.org/publish/requirements/gpg/
    def signingKey = '<your signing key>'
    def signingPassword = '<your signing password>'
    useInMemoryPgpKeys(signingKey, signingPassword)

    sign publishing.publications.mavenJava
}

mavenCentral {
    repoDir = layout.buildDirectory.dir('repos/bundles')
    // Token for Publisher API calls obtained from Sonatype official,
    // it should be Base64 encoded of "username:password".
    authToken = '<your token>'
    // Whether the upload should be automatically published or not. Use 'USER_MANAGED' if you wish to do this manually.
    // This property is optional and defaults to 'AUTOMATIC'.
    publishingType = 'AUTOMATIC'
    // Max wait time for status API to get 'PUBLISHING' or 'PUBLISHED' status when the publishing type is 'AUTOMATIC',
    // or additionally 'VALIDATED' when the publishing type is 'USER_MANAGED'.
    // This property is optional and defaults to 60 seconds.
    maxWait = 60
}

For details on the requirements for publishing Maven components, refer to the Sonatype official documentation.

Upload the bundle by using the publish and publishToMavenCentralPortal tasks:

$ ./gradlew publish publishToMavenCentralPortal