Step-by-step teaching you to share an open source project to the Maven central warehouse

Source: Internet
Author: User
Tags gpg maven central sonatype

you are welcome to follow my Sina Weibo blog: Http://weibo.com/kifile

Reprint Please indicate the source (http://blog.csdn.net/kifile)


Believe a lot of programs ape friends have more or less written some common library files, there are many people will be the spirit of open source to share the code like Github and other code hosting site.

In fact, when we share the code, the purpose is to let more people use, but if it is only on GitHub these tools to download and use, in fact, many people will feel very troublesome, then there is a way to help us do not download the source code on GitHub, the use of these codes?

It is possible to answer naturally, similar to maven,gradle (in fact, the mechanism that Gradle gets the code is also based on Maven) This automated build tool can help you get the specified code from the Web and configure it to your project, so we can just upload our code to Maven In a central repository, someone can reference your project through a few lines of code.

Next, we'll step through how to upload an open source project to the Maven central repository.

First, let me briefly introduce my own platform environment configuration:

Platform:macos Yosemite.

Ide:android Studio 1.0.2.

Project:android Library.

In fact, other platforms are very similar, but for the sake of convenience, I will briefly introduce the above environment configuration based on the sharing steps.

Let's put Maven's official guide. Address: http://central.sonatype.org/pages/ossrh-guide.html

1. Apply for Sonatype account and establish project request

Maven's related management work seems to be managed to sonatype.org this site for processing, when we want to add a new project to the Maven central Warehouse, we must first apply for an account here, and provide the corresponding project information.

The address of the application account is here: Https://issues.sonatype.org/secure/Signup!default.jspa

After the application is completed, we need to provide the corresponding project information, the address is here: https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134

Fill in the Project information page although is English, but is very simple, a lot of input boxes below are the corresponding input prompt, so I do not do more introduction, Figure 1 is a simple introduction to fill in the relevant information:



Figure 1 providing project-related information

After clicking Create, you will enter a Jira page (Sonatype use Jira to track each project's progress), and you will receive an e-mail message in the mailbox you are registering with, and the task is created and waiting to be processed.

The next thing we need to do is wait, the MAVEN project can only be formally released after Sonatype's own audit, according to the official online description is about two days, but my project was sent early the next morning to notify me of the success of the creation, for their speed point of praise.


2. Upload the project to the Maven Central warehouse

If you receive a sonatype feedback email confirming that you have created a new project for you, you are ready to start uploading your project.

I'm going to upload my new Android Click Gallery File to the Maven repository, because I'm using Android Studio, so I configured it directly in my Library project's Gradle.build file.

First add the following code to the tail of the Gradle.build file:

Apply plugin: ' maven ' Apply plugin: ' signing ' signing {sign configurations.archives}group = ' Com.kifile ' archivesbasename                = "Materialview" Version = "1.0" Uploadarchives {repositories {mavendeployer {beforedeployment {            Mavendeployment deployment, Signing.signpom (Deployment); } Repository (URL: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {Authenticat Ion (Username:ossrhusername, Password:ossrhpassword)} snapshotrepository (url: "Https://oss.sonatyp            E.org/content/repositories/snapshots/") {Authentication (username:ossrhusername, Password:ossrhpassword) } pom.project {name ' Materialview ' packaging ' aar ' des Cription ' This was build to let the view looks like a material design widgets when touched.  ' URL ' https://github.com/Kifile/MaterialView ' SCM {                  Connection ' scm:git:https://github.com/kifile/materialview.git ' developerconnection '                Scm:git:https://github.com/kifile/materialview.git ' url ' https://github.com/Kifile/MaterialView.git ' } licenses {license {name ' The Apache license, Ver                Sion 2.0 ' url ' http://www.apache.org/licenses/LICENSE-2.0.txt '} } developers {developer {id ' kifile ' nam        E ' kifile Chou ' email ' [email protected] '}} }    }}

In the code above, please change the group,archivebasename,version in the root domain and the related description information in Uploadarchives#pom.project to your own.

This information will be automatically packaged as a Maven project and encapsulated in the next upload.

Here we have configured the corresponding version information, next we need to configure the upload required signature and password and other related information.

First we need to create a GPG signature key and upload the public key to the specified server.

Under MacOS, we can download a tool called Gpgtools (http://www.gpgtools.org) to generate our signature files.

After installing the tool, we can see in the Launchpad a software called GPG keychains, open, we choose to create a new secret key, see Figure 2:


Figure 2 creating a GPG secret key

After clicking New, after filling in the corresponding information, click Generate key, we get the signature key, and then right-click on the created secret key to the key server. The local public key can be uploaded to the specified server, see Figure 3.


Figure 3 uploading a public key to a public server

Once the upload is complete, we can formally configure the signature information and your Maven account information, and we will create a new gradle.properties file under the Library Module's root directory, which reads as follows:

signing.keyid= input keyidsigning.password= Enter your secret key password signing.secretkeyringfile=/users/your username when the new key is complete/.gnupg/ Secring.gpgossrhusername= your account name on Sonatype ossrhpassword= your password on the Sonatype


Now, you have successfully configured the upload information, through the command line, into the Library Module directory, input gradle uploadarchives will be able to upload your files to the Maven Central Library.


3. Publish your App

Do you think it's over when you upload to Maven's central library?

It's not over, so far, you've just uploaded your files to a Maven private server that can't be accessed by anyone else. If you want to officially publish your app, continue with the steps below.

A. Go to the Maven Project console

Enter the following address: https://oss.sonatype.org/, and use the Sonatype account password to log in in the upper right corner.

B. Find the item you uploaded
If you log in successfully, in the left navigation bar, you will see an option called Staging repositories, click on him and you will find a lot of list options appearing, such as 4.


Figure 4 Warehouse List

Depending on the name of the list, you will find a Groud ID minus the dot number followed by a four-digit number named Repository, for example, here is called comkifile1000, select it, you will find the top of the Close button lit, when you confirm the upload is correct, you can click The Close button closes the repository and does not allow uploading again. If the switch is successful, you will find that when you click Refresh, the release button is lit and you can click it to publish. If the shutdown fails, you can look at the interface below, look for the reason for the failure, upload the code again, and post it off.


Here, the entire MAVEN project release process is over.

Please note that the release is not effective in real time, my code is about 3 hours or so before it can be retrieved in the Maven central repository, so if you do not retrieve it in time, please try again later.

Step-by-step teaching you to share an open source project to the Maven central warehouse

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.