abhi10jul / UploadToMavenCentral

[Example] Base repository to demonstrate the process of uploading an aar/jar to maven central.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Upload to MavenCentral

Show some ❤️

GitHub stars GitHub forks GitHub watchers GitHub followers
Twitter Follow

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

  1. Create an Android project or open an existing one in Android Studio

  2. 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.

  3. Create and add a new module and choose Android Library.

    Goto File>New>New Module.. and select Android Library.

  4. Implement your library code inside the library module you created in the last step.

  5. Next add the library module as a dependency to the app module.

    1. Goto File>Project Structure..
    2. Select app module in the sidebar
    3. Select the Dependencies tab
    4. At the bottom is a + icon, click that and select Module dependency and select your library module.
    5. Press apply or ok.
  6. Add the plugin by Chris Banes to your library's build.gradle

NOTE: Below is a fork of the orginal 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
VERSION_NAME=1.0.0
VERSION_CODE=1
POM_NAME=<Library_Name>
POM_ARTIFACT_ID=<library_name_smallcaps>

POM_DESCRIPTION=<library_description>
POM_URL=https://github.com/<username>/<repo_name>
POM_SCM_URL=https://github.com/<username>/<repo_name>
POM_SCM_CONNECTION=scm:git@github.com:<username>/<repo_name>.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:<username>/<repo_name>.git
  1. 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 
    username@example.com # Use your email
  1. 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.com/<github_username>/<project_name> SCM url : https://github.com/<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 gradle.properties on your local machine at location ~/.gradle/gradle.properties and include

     NEXUS_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
    
  1. Run in terminal to publish your artifacts
./gradlew build clean uploadArchive
  1. Login into Nexus Repository Console and search for your package name.

  2. Close the staged artifact.[wait]

  3. Release the closed artifact (keep drop artifact selected).[wait]

  4. Wait for some hours before everything gets synced with MavenCentral.

  5. To use the published library you have do something like below

dependencies {
    compile 'com.github.nisrulz:awesomelib:1.0'
}
  1. 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 readme.

If you found this example helpful or you learned something from the source code and want to thank me, consider buying me a cup of ☕

  • PayPal
  • Bitcoin Address: 13PjuJcfVW2Ad81fawqwLtku4bZLv1AxCL

License

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.

About

[Example] Base repository to demonstrate the process of uploading an aar/jar to maven central.

License:Apache License 2.0


Languages

Language:Java 100.0%