A gradle plugin to easily upload libraries to MavenCentral for distribution.
Apply the plugin in your build.gradle:
Groovy
plugins {
id 'dev.sarquella.mavencentral-publisher' version '1.0.0'
}Kotlin
plugins {
id("dev.sarquella.mavencentral-publisher") version "1.0.0"
}Add the following to your local.properties file, or create your own *.properties file (e.g. maven-publish.properties). If you use a custom properties file, you should specify its path in the publication configuration (See next step).
Important: Make sure it is listed in your
.gitignorefile to avoid publishing your credentials
ossrhUsername=OSSRH_USERNAME
ossrhPassword=OSSR_PASSWORD
signingKeyId=SIGNING_KEY_ID
signingKeyPassword=SIGNING_KEY_PASSWORD
signingKeyFile=SIGNING_KEY_FILE.gpg
Replace with your own values:
OSSRH_USERNAMEandOSSR_PASSWORDare your Sonatype Jira's account credentials. See moreSIGNING_KEY_ID,SIGNING_KEY_PASSWORDandSIGNING_KEY_FILEare your GPG key id, passphrase and file path respectively. See more
Add the following to your build.gradle and replace with your own values:
Note: Your library will be finally published as groupId:artifact:version
Only the mandatory parameters are listed in this example. For a full list of all the available parameters, as well as a brief explanation of each, see the Parameters section
Groovy
mavenCentralPublication {
groupId = 'GROUP_ID'
artifact = 'ARTIFACT'
version = 'VERSION'
repoUrl = 'REPO_URL'
vcsUrl = 'VCS_URL'
developer {
id = 'DEVELOPER_ID'
name = 'DEVELOPER_NAME'
email = 'DEVELOPER_EMAIL'
}
license {
name = 'LICENSE_NAME'
url = 'LICENSE_URL'
}
}Kotlin
mavenCentralPublication {
groupId.set("GROUP_ID")
artifact.set("ARTIFACT")
version.set("VERSION")
repoUrl.set("REPO_URL")
vcsUrl.set("VCS_URL")
developer {
id.set("DEVELOPER_ID")
name.set("DEVELOPER_NAME")
email.set("DEVELOPER_EMAIL")
}
license {
name.set("LICENSE_NAME")
url.set("LICENSE_URL")
}
}Run the following command to upload the library to MavenCentral
./gradlew publishToMavenCentral
-
groupId: Library's group name (e.g., com.company.library) -
artifact: Library's concrete artifact name -
version: Library's current version (e.g., 1.0.0) -
description[Optional]: Short description about the library. If not set, defaults to "-" char. -
repoUrl: Code repository url (e.g., https://github.com/<username>/<repository>) -
vcsUrl: Version control url (e.g., https://github.com/<username>/<repository>.git) -
webUrl[Optional]: Library's website url. If not set, defaults torepoUrlvalue. -
developerid: Library's developer idname: Library's developer nameemail: Library's developer email
-
licensename: Library's license name (e.g., The Apache Software License, Version 2.0)url: Library's license url (e.g., http://www.apache.org/licenses/LICENSE-2.0.txt)
-
archiveFileName[Optional]: Custom build output file name if different from defaults (e.g. mylibrary-<flavor>-release.aar). In Android, defaults to <project>-release.aar. In non-Android, defaults to <project>-<version>.jar -
propertiesFile[Optional]: Path to custom *.properties file where credentials are defined. If not set, defaults to local.properties.
Thanks to Márton Braun for this great article which this plugin is inspired on.
Copyright 2021 Adrià Sarquella Farrés
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.