Skip to content

Latest commit

 

History

History
70 lines (56 loc) · 2.12 KB

README.md

File metadata and controls

70 lines (56 loc) · 2.12 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>'
}

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