Base repository to demonstrate the process of uploading an aar
/jar
to MavenCentral.
Blog Post : Guide to publishing your Android Library via MavenCentral
The process is as follows
-
Create an Android project or open an existing one in Android Studio
-
Init the project with git and also create a repo on Github for the same. Each step here onwards represent a commit and should be pushed to github.
-
Create and add a new module and choose
Android Library
.Goto
File>New>New Module..
and selectAndroid Library
. -
Implement your library code inside the library module you created in the last step.
-
Next add the library module as a dependency to the app module.
- Goto
File>Project Structure..
- Select
app
module in the sidebar - Select the
Dependencies
tab - At the bottom is a
+
icon, click that and selectModule dependency
and select yourlibrary
module. - Press
apply
orok
.
- Goto
-
Add the plugin by Chris Banes to your library's
build.gradle
file at the endNOTE: Below is a fork of the original script written by Chris Banes.
apply from: 'https://raw.github.com/nisrulz/gradle-mvn-push/master/gradle-mvn-push.gradle'
and define the required variables in the
gradle.properties
.# Properties used by gradle maven-push plugin # Library info GROUP=<group_name> VERSION_NAME=1.0.0 VERSION_CODE=1 # POM info POM_NAME=<Library_Name> POM_ARTIFACT_ID=<library_name_smallcaps> POM_DESCRIPTION=<library_description> POM_URL=https:/<username>/<repo_name> POM_SCM_URL=https:/<username>/<repo_name> POM_SCM_CONNECTION=scm:[email protected]:<username>/<repo_name>.git POM_SCM_DEV_CONNECTION=scm:[email protected]:<username>/<repo_name>.git
-
Setup GPG and generate yourself a key.
-
Now list your gpg keys
$ gpg --list-keys
There the first line will be like pub XXXXX/YYYYYYYY . Remember that ‘YYYYYYYY’ part, it’s you key ID.
-
Next, publish your keys
$ gpg --keyserver hkp://keyserver.ubuntu.com --send-keys YYYYYYYY $ gpg --keyserver hkp://pgp.mit.edu --send-keys YYYYYYYY
-
To ensure your keys were published
$ gpg --keyserver hkp://pgp.mit.edu --search-keys [email protected] # Use your email
-
-
Setup Sonatype account
-
Create a JIRA account on Sonatype
-
Once you are logged in, create a new issue
-
Fill out the form as below
Group Id : com.github.<github_username> Project URL : https:/<github_username>/<project_name> SCM url : https:/<github_username>/<project_name>.git Username : <sonatype_username> Already Synced to Central : No
-
Next hit submit. After you submit, it can take up to 2 business days to process your issue. Then you will receive a confirmation that your configuration has been prepared and you can publish your library.
IMPORTANT : Do not deploy until after you have received an e-mail notice indicating that the ticket is Resolved.
-
Update the global
gradle.properties
on your local machine at location~/.gradle/gradle.properties
and includeNEXUS_USERNAME=sonatype_username NEXUS_PASSWORD=sonatype_password signing.keyId=gpg_key_id signing.password=gpg_password signing.secretKeyRingFile=/Users/username/.gnupg/secring.gpg org.gradle.daemon=true
-
-
Run in terminal to publish your artifacts
./gradlew build clean uploadArchive
-
Login into Nexus Repository Console and search for your package name.
-
Close the staged artifact.[wait]
-
Release the closed artifact (keep drop artifact selected).[wait]
-
Wait for some hours before everything gets synced with MavenCentral.
-
To use the published library you have do something like below
dependencies { implementation 'com.github.nisrulz:awesomelib:1.0' }
-
Let the world know of your AwesomeLib 😄
- Add a readme that explains how to integrate and use your Awesome library
- Add a license block as in this repo
- Promote your lib on social media so that others can know about it.
- Always add a working sample app in your project that demonstrates your library in use.
- Add screenshots if possible in your read
If you appreciate my work, consider buying me a cup of ☕ to keep me recharged 🤘 [PayPal]
Copyright 2016 Nishant Srivastava
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.