Skip to content
Gradle plugin that configures an uploadArchives task to automatically upload all of your Java, Kotlin or Android libraries to any Maven instance.
Kotlin Groovy Shell Java
Branch: master
Clone or download
Jawnnypoo and vanniktech Update README with signing instructions (#73)
* Update README with signing instructions

* Update README.md

Co-Authored-By: Niklas Baudy <niklas.baudy@vanniktech.de>
Latest commit 64dab81 Nov 6, 2019

README.md

gradle-maven-publish-plugin

Gradle plugin that creates an uploadArchives task to automatically upload all of your Java, Kotlin or Android libraries to any Maven instance. This plugin is based on Chris Banes initial implementation and has been enhanced to add Kotlin support and keep up with the latest changes.

Set up

module/build.gradle

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.vanniktech:gradle-maven-publish-plugin:0.8.0'
  }
}

apply plugin: "com.vanniktech.maven.publish"

Information: This plugin is also available on Gradle plugins

Snapshots

Can be found here. Current one is:

classpath 'com.vanniktech:gradle-maven-publish-plugin:0.9.0-SNAPSHOT'

Configuration

Those are all the available configurations - shown with default values and their types. More information can be found in the Documentation of the Extension.

mavenPublish {
  targets {
    uploadArchives {
      releaseRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
      snapshotRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
      repositoryUsername = null // This defaults to either the SONATYPE_NEXUS_USERNAME Gradle property or the system environment variable.
      repositoryPassword = null // This defaults to either the SONATYPE_NEXUS_PASSWORD Gradle property or the system environment variable.
      signing = true // This defaults to true. GPG signing is required by mavenCentral. If you are deploying elsewhere, you can set this to false.
    }
  }
}

Once you've configured this and defined the typical pom attributes via Gradle properties you can upload your library using the uploadArchives task.

If you need to upload to multiple repositories you can also add additional targets.

mavenPublish {
  targets {
    uploadArchives {
       // Configure as above.
    }

    internalRepo {
       // Configure as above.
    }

    betaRepo {
       // Configure as above.
    }
  }
}

This will create uploadArchivesInternalRepo and uploadArchivesBetaRepo tasks.

Note: To prevent looping behavior, especially in Kotlin projects / modules, you need to run the uploadArchives task with --no-daemonand --no-parallel flags:

./gradlew uploadArchives --no-daemon --no-parallel

Note: Other than the common maven plugin you must do the release steps at sonatype manually.

Sample

This Gradle plugin is using itself to publish any of the updates. It applies a previously released version in the build.gradle just as mentioned above and sets the Gradle properties in this gradle.properties.

If you require your binary to be signed with GPG (mavenCentral requires this for instance), please add the following Gradle properties. It's best to place them inside your home directory, $HOME/.gradle/gradle.properties.

signing.keyId=12345678
signing.password=some_password
signing.secretKeyRingFile=/Users/yourusername/.gnupg/secring.gpg

License

Copyright (C) 2018 Vanniktech - Niklas Baudy

Licensed under the Apache License, Version 2.0

You can’t perform that action at this time.