Skip to content

BoBkiNN/sonatype-publisher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

171 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

sonatype-publisher

This simple plugin builds and uploads existing maven publication to Maven Central Repository using Portal Publisher API

Tested on Gradle 8.14

Usage:

  1. Add and apply plugin
  2. Configure extension:
// add imports
import xyz.bobkinn.sonatypepublisher.PublishingType
import xyz.bobkinn.sonatypepublisher.sonatypePublish

sonatypePublish {
    // specify maven central repository token username and password
    username = System.getenv("MAVEN_CENTRAL_USERNAME")
    password = System.getenv("MAVEN_CENTRAL_PASSWORD")
    publishingType = PublishingType.USER_MANAGED // or AUTOMATIC so deployments released when ready

    // using shortcut method to register central publish for maven publication and same name
    registerMaven(publishing.publications.named("main", MavenPublication::class))
}
  1. Configure your publication with correct POM, sources, javadocs and signing to match maven central requirements
  2. Run task publish<publication name>ToSonatype

Adding to project:

Java 17 or later required
Setup Gradle Plugin Portal plugin repository in settings.gradle.kts:

pluginManagement {
    repositories {
        gradlePluginPortal() // add if not already
    }
}

Or setup using JitPack - How To section.

Add then apply plugin in build.gradle.kts:

plugins {
    id("io.github.bobkinn.sonatype-publisher") version "2.2.4"
}

About fork:

Based on sonatype-maven-central-publisher, I have introduced critical changes, code improvements and fixes, targeting different goal to work with existing publications.

Fixed issues:

There are also more plans for plugin in TODO file

Available Options

Each publication can be configured via the SonatypePublishExtension using the following options:

  • publishingType (AUTOMATIC | USER_MANAGED) Determines how the publication is uploaded to Sonatype.

  • additionalTasks (List<String>) Extra tasks to run when building artifacts for this publication.

    Currently, this tasks results are not included in bundle

  • additionalAlgorithms (List<String>) Extra hash algorithms to include in the bundle.

    MD5 and SHA-1 are always included.

  • username / password (String) Sonatype credentials for authentication.

  • publication (MavenPublication) The Gradle publication whose artifacts will be built and published.

Registering a Maven publication:

sonatypePublish.registerMaven("myLib", myPublication) {
    it.publishingType = PublishingType.AUTOMATIC
    it.additionalTasks = listOf("someTask")
    it.additionalAlgorithms = listOf("SHA-256")
}
  • Credentials and other internal settings are handled automatically by the plugin.
  • Users usually only need to specify the publication and optional additional tasks or hash algorithms.

General Deployment Tasks

These tasks provide manual control and bulk automation for Sonatype Portal deployments. They are not bound to specific project configurations β€” instead they operate using stored deployment IDs and Sonatype credentials defined in your SonatypePublishExtension.

Deployments statuses is stored in <root project>/build/sonatypePublish/deployments.json: current - currently unpublished deployments. They are used in tasks published - published deployments, exists just for informational purposes

All tasks use credentials defined in your plugin extension:

sonatypePublish {
    username = "your-username"
    password = "your-password"
}

πŸ”Ž checkDeployments

Fetches the latest status of stored deployments and prints their current state.

What it does

  • Updates deployment statuses from Sonatype Portal
  • Prints details (state, name, errors if present)
  • Can target a specific deployment or all stored ones

Usage

# Check all current deployments
./gradlew checkDeployments

# Check a specific deployment
./gradlew checkDeployments -PdeploymentId=<deploymentId>

Behavior

  • Removes deployments no longer present on the portal
  • Moves published deployments to the published list
  • Updates statuses for active deployments

πŸš€ publishDeployment

Publishes a specific deployment using its deployment ID.

Usage

./gradlew publishDeployment -PdeploymentId=<deploymentId>

Behavior

  • Triggers publish through the Sonatype Portal API
  • Updates stored deployment state to PUBLISHING
  • Fails if deploymentId is missing or blank

❌ dropDeployment

Drops a specific deployment from the portal.

Usage

./gradlew dropDeployment -PdeploymentId=<deploymentId>

Behavior

  • Calls the Portal API to drop the deployment
  • Removes it from the stored current deployment list

🧹 dropFailedDeployments

Fetches latest statuses and automatically drops all failed deployments.

Usage

./gradlew dropFailedDeployments

Behavior

  • Updates deployment status first
  • Drops only deployments marked as failed
  • Saves updated deployment data afterward

βœ… publishValidatedDeployments

Fetches latest statuses and publishes all validated deployments automatically.

Usage

./gradlew publishValidatedDeployments

Behavior

  • Updates deployment status first
  • Publishes deployments marked as validated
  • Updates their state to PUBLISHING
  • Saves updated deployment data

How it works

This pipeline builds and publishes a Maven publication to Sonatype Central. It runs automatically when executing the final publish task.

Steps:

  1. BuildPublicationArtifacts

    • Builds all artifacts for the publication.
    • Depends on underlying build tasks and any extra configured tasks.
  2. AggregateFiles

    • Copies all artifacts to a temporary directory.
    • Renames files to standard Maven conventions.
  3. ComputeHashes

    • Generates MD5 and SHA-1 hashes for all aggregated files.
    • Optional additional hash algorithms can be configured.
  4. CreateZip

    • Packages all files and hashes into a single zip archive for upload.
  5. PublishToSonatypeCentral

    • Uploads the zip bundle to Sonatype Nexus.
    • Saves the deployment ID for tracking.

Pipeline Flow:

buildArtifacts β†’ aggregateFiles β†’ computeHashes β†’ createZip β†’ publishToSonatype

About

Publish your MavenPublications to Maven Central Repository

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages