What it is
gradle-maven-publish-plugin is a Kotlin Gradle plugin licensed under Apache-2.0. It creates a publish task to upload Java, Kotlin, or Android libraries to any Maven instance, including Maven Central or other Nexus instances. The project lives in the Gradle build ecosystem and covers Android, Java, Kotlin JVM, and Kotlin Multiplatform libraries.
The problem is that publishing differs across project types. The Android Gradle Plugin provides an API to configure publishing, java-library provides an API too, and Kotlin Multiplatform does most things automatically but not everything. This plugin gives a unified approach and configures as much as possible while still allowing manual configuration where needed.
Key capabilities
- It creates a publish task for uploading Java, Kotlin, or Android libraries to any Maven instance.
- It supports output from java, java-library, java-platform, java-gradle-plugin, com.android.library, com.android.fused-library, com.android.kotlin.multiplatform.library, org.jetbrains.kotlin.jvm, org.jetbrains.kotlin.multiplatform, com.gradle.plugin-publish, and version-catalog plugins.
- It provides Maven Central integration through dedicated APIs and supports automatic releasing without web interface interaction.
- It supports in-memory GPG signing keys using required environment variables for CI artifact signing.
- It can be configured through Gradle properties that apply to all subprojects.
- It offers a base plugin that applies no default configuration and allows most customization.
- It publishes Android and Kotlin libraries with sources and javadoc.
Who uses it and how
- Library authors publishing Android or Kotlin libraries to Maven Central can use the dedicated APIs to configure metadata, signing, and release behavior.
- Teams with mixed Gradle projects can apply one publishing approach across Gradle plugin projects, Android libraries, and Kotlin Multiplatform modules.
- CI pipelines can set GPG key environment variables and Gradle properties to sign and publish artifacts without manual web interface steps.
- Organizations publishing to other Nexus instances can follow the other Maven repository setup instead of Maven Central.
- Maintainers who need the most customization can start from the base plugin and configure what is published.
Getting started
Add the plugin to a Gradle build and follow the Maven Central setup guide or the other Maven repositories guide. For projects that need no defaults, apply the base plugin and configure publishing manually.
When to use it — and when not to
Use it when a project needs one publishing setup across Java, Kotlin, Android, Gradle plugin, and Kotlin Multiplatform modules, especially for Maven Central or Nexus. Do not choose it if a team wants a fully hosted publishing service, because it still requires a Maven repository, credentials, GPG keys, and Gradle configuration. The plugin also leaves some parts for manual configuration, so projects that need complete control should use the base plugin and wire publishing details themselves.
project readme (upstream, from github) — read inline
gradle-maven-publish-plugin
Gradle plugin that creates a publish 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.
Setup
For modifying what is getting published see configuring what to publish.
There is also a base plugin that doesn't apply any
default configuration and allows the most customization.
Supported plugins
The output of the following Gradle plugins is supported to be published with this plugin:
com.android.fused-library
com.android.kotlin.multiplatform.library
com.android.library
com.gradle.plugin-publish
java
java-gradle-plugin
java-library
java-platform
org.jetbrains.kotlin.jvm
org.jetbrains.kotlin.multiplatform
version-catalog
Advantages over maven-publish
Gradle ships with the maven-publish and many other plugins like the Android Gradle Plugin or the Kotlin Multiplatform
plugin directly integrate with, so why should you use this plugin?
- No need to know how publishing works for different project types. AGP provides an API to configure publishing,
java-library too, Kotlin Multiplatform does most things automatically but not everything. This plugin configures
as much as possible on its own.
- An unified approach for all kinds of projects. Some parts require manual configuration and for those we provide an API
that works regardless of whether this is a Gradle plugin, an Android library or a Kotlin Multiplatform project. This
is especially useful for projects that combine multiple of these.
- Maven central integration. The plugin makes it easy to configure publishing to Maven Central with dedicated
APIs to set it up and configure everything that is required. It also supports automatic releasing without requiring
any interaction with the web interface.
- In memory GPG signing keys. Easily sign artifacts on CI by simply setting the required environment variables,
no extra setup required.
- Gradle property based config. Easily configure the plugin with Gradle properties that will apply to all
subprojects
License
Copyright (C) 2018 Vanniktech - Niklas Baudy
Licensed under the Apache License, Version 2.0