Use Gradle to publish an open-source project to Maven Central

Source: Internet
Author: User
Tags gnupg maven central sonatype

Use Gradle to publish an open-source project to Maven Central

Those who have used Android Studio should be impressed by Gradle's powerful build system. Gradle can easily integrate various open-source libraries and compile automated script processing tasks, it is a great trend to replace Maven. In my spare time, I was maintaining an open-source project, and I also received several PR requirements to release it to Maven Central for Gradle. So I found some articles and finally published the project.

1. Apply for the Maven Central release permission

Put the main information of your project into issue, and set Group Id carefully. After the application is approved, you can only publish the project under your Group Id.

After the issue is created, wait for a few days and an email will be sent to you after it passes.

2. Compile the Gradle release script

Thanks to the script provided by Chris Banes, I made some modifications and made a version of my own.

https://github.com/SpecialCyCi/AndroidResideMenu/blob/master/maven_push.gradle

Put the above script under the root directory of the project, go to the module directory where the Open Source library is located, and add the following code build. gradle:

apply from: '../maven_push.gradle'

Modify gradle. properties in the project root directory and add the project information:

VERSION_NAME=1.6VERSION_CODE=8POM_GROUP_ID=com.specyciPOM_DESCRIPTION=....POM_URL=https://github.com/SpecialCyCi/AndroidResideMenuPOM_SCM_URL=https://github.com/SpecialCyCi/AndroidResideMenuPOM_SCM_CONNECTION=scm:git@github.com:SpecialCyCi/AndroidResideMenu.gitPOM_SCM_DEV_CONNECTION=scm:git@github.com:SpecialCyCi/AndroidResideMenu.gitPOM_LICENCE_NAME=The MIT License (MIT)POM_LICENCE_URL=https://raw.githubusercontent.com/SpecialCyCi/AndroidResideMenu/master/LICENSEPOM_LICENCE_DIST=repoPOM_DEVELOPER_ID=specialcyciPOM_DEVELOPER_NAME=Special LeungPOM_INCEPTION_YEAR=2013

Finally, add the compilation information to the module Directory of the open-source library to gradle. properties:

POM_NAME = AndroidResideMenu
POM_ARTIFACT_ID = residemenu
POM_PACKAGING = aar

3. Download GPGTools and create the Signing Key

The Signing Key can be regarded as a signature of the author's information. The signature is divided into public and private. The public key must be uploaded to keyservers.net for storage.

Generate the Signing Key in the local command line:

➜  AndroidResideMenu git:(master) gpg --gen-keyPlease select what kind of key you want:   (1) RSA and RSA (default)   (2) DSA and Elgamal   (3) DSA (sign only)   (4) RSA (sign only)Your selection? 1RSA keys may be between 1024 and 8192 bits long.What keysize do you want? (2048)Requested keysize is 2048 bitsPlease specify how long the key should be valid.         0 = key does not expire      <n>  = key expires in n days      <n>w = key expires in n weeks      <n>m = key expires in n months      <n>y = key expires in n yearsKey is valid for? (0) 0Key does not expire at allIs this correct? (y/N) yGnuPG needs to construct a user ID to identify your key.Real name: Special Leung(Testing)Email address: specialcyci+test@gmail.comComment: This is just a testing key.You selected this USER-ID:    "Special Leung(Testing) (This is just a testing key.) <specialcyci+test@gmail.com>"Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? OYou need a Passphrase to protect your secret key....pub   2048R/8C1761A2 2015-01-24      Key fingerprint = xxxuid       [ultimate] Special Leung(Testing) (This is just a testing key.) <specialcyci+test@gmail.com>sub   2048R/E32D1186 2015-01-24

Then upload the public key to keyservers.net:

$ gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 8C1761A2gpg: sending key 8C1761A2 to hkp server pool.sks-keyservers.net

Finally, fill in the information of the Signing Key ~ /. Gradle/gradle. properties:

# Viewing key information ~ Gpg -- list-secret-keys/Users/special /. gnupg/secring. gpg # <-key Directory ----------------------------- sec 2048R/8C1761A2 2015-01-24 #<-8C1761A2 is the key iduid Special Lenung (Testing) (This is just a testing key .) <specialcyci + test@gmail.com> ssb 2048R/E32D1186 2015-01-24
# ~/.gradle/gradle.propertiessigning.keyId=8C1761A2signing.password=passwordsigning.secretKeyRingFile=/Users/special/.gnupg/secring.gpgnexuSUSErname=usernamenexusPassword=password
4. Execute the Gradle release script
%GRADLE_HOME%/bin/gradle uploadArchives

If the version name contains a SNAPSHOT string, the project will be uploaded to the snapshots node. If you want to release it to the official repository of Maven Central, remove the SNAPSHOT from the version name, the SNAPSHOT version does not require Step 5 Central Sync.

Snapshots node: https://oss.sonatype.org/content/repositories/snapshots

5. Activate the Maven Central Sync Process

If Step 1 is successful, you can see the project in stagingRepositories of oss.sonatype.org (https://oss.sonatype.org/), and then press Close to prepare the release project.

After successfully closing the project, go to the issue address in the first step and send a comment to ask the staff to enable the Sync process for you. Generally, there will be a reply within one business day.

After the staff can reply, execute the "Release" operation. If there is no accident, you can search for your project at search.maven.org in two hours.

6. Conclusion

In general, publishing is quite convenient. Manual review may waste some time and may encounter some problems occasionally. However, sonatype is very professional. After you tell them your problems, you can get an effective solution.

However, Android Studio recently uses jCentral as the default node, and may have to wait for jCentral next time.

Maven official guide _ Chinese full version clear PDF

Maven 3.1.0 release, Project Build Tool

Install Maven in Linux

Maven3.0 configuration and simple use

Set up sun-jdk and Maven2 in Ubuntu

Get started with Maven

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.