Release Maven components to the central repository

Source: Internet
Author: User

I have been using Maven for a while. whether you agree or not, I firmly believe that Maven is a great software project. Using it can save a lot of time, especially when it is used with git, just like the combination of Sichuan food's pepper and sea pepper, it is unparalleled and will definitely fall in love with it after it is used. In my previous blog, I described how to use git (egit plug-in eclipse) to manage projects. Next I will explain how to publish components to the maven central repository. If you still don't know anything about Maven or git (you won't be able to use them in time, but you should be familiar with them), you should know about it.

Here it should be noted that my release process is based on the two blogs in open source China (@ Huang Yong's http://my.oschina.net/huangyong/blog/226738and @ Lu Xiaolei's http://my.oschina.net/looly/blog/270767), here I would like to express my gratitude to them.

I will not talk much about it. The following is the official start.

1. Register a sonatype account

Maven central repository is maintained by a company called sonatype, which needs to go to the https://issues.sonatype.org/secure/Signup before releasing components! Default. JSpA: register an account, remember your username and password, and use it later.

At the same time, you also need to remember an address, in the future in the query of their own component Status and some operations to use, https://oss.sonatype.org /.

2. Submit a publishing application

Submit the application, here is the form of creating an issue, creating address: https://issues.sonatype.org/secure/CreateIssue.jspa? Issuetype = 21 & pid = 10134.

Note the following when entering the issue information:

A) "group ID" means that when someone else uses your component. part of the coordinates to be located in the XML file, and it should be in reverse order of your site URL. Refer to the Java package naming rules, sometimes the staff will want you to confirm whether you are the owner of the site URL. here, because I have purchased the ownership of the songxinqiang.cn domain name, I fill in "CN. songxinqiang"

B) "project URL" is the site of the project, which is generally used as a description.

C) the source code URL of the "scm url" component, which is easy for others to view the source code. Of course, this must be accessible through the public network. Do not use any internal SVN address or something, I use [email protected] from open-source China. We also recommend that you use it.

There is nothing else. After the submission, wait for the staff to leave for confirmation. Sometimes the staff will ask you something you don't have clearly stated, just answer it. It should be noted that the staff of this system work in the United States. After my waiting and observation, they will start to work and process issue at Beijing time, so don't query the status before this time. People are not at work yet (I will tell you that I submitted it around AM, check once every half an hour until the staff replies to me ).

Wait until the staff reply to you under the issue you created and say "the configuration has been modified ......" (There are several links) It indicates that the approval has been passed, and you can upload the component.

3. Preparation before uploading

Before uploading a component, you must prepare a GPG to sign the published file.

Windows users to http://www.gpg4win.org/download.html to download the Gpg4win-Vanilla version to use, Linux directly install GPG package on the line.


gpg --gen-key
You need to enter the name, email address, and other fields. You can use the default value for other fields. In addition, you also need to enter a passphase, which is equivalent to the password of A keystore. Do not forget it or tell others, it is best to remember, because it will be used later.


For more information, see @ Huang Yong's blog (http://my.oschina.net/huangyong/blog/226738 ).


4. Configure Maven

Find the maven configuration file <mvn_home>/CONF/settings. XML: Find the <servers> node in the configuration file. The node is annotated by default. We will add a <servers> Configuration outside the pig.

<Servers> <Server> <ID> OSS </ID> <username> User Name </username> <password> password </password> </Server> </servers>
The ID here will be used in POM. XML in the future, so be sure to remember that the user name and password are the user name and password registered on sonatype.


5. Configure Pom. xml

Next is the first thing to do, Pom. XML is the key configuration of a Maven project. All configurations of a project can be described in this file. All configurations in the file have default values. That is to say, all configurations are optional, however, in order to publish the component to the central repository, We must configure some key information. Otherwise, the component will not pass after it is released.

The critical information must be clear, including: name, description, URL, licenses, developers, SCM, and other basic information. In addition, the maven profile function is used only when release is used, create source code package, create document package, and use GPG for digital signature. In addition, the IDs in snapshotrepository and repository must be consistent with those in settings. xml.

You can directly inherit a Configuration component of your own, and then define a coordinate yourself. My component coordinates are:


<groupId>cn.songxinqiang</groupId><artifactId>oss-parent</artifactId><version>1.0</version>
6. Upload Component


After the component is compiled, you can upload and publish the component. Enter the path of the Project Pom. XML in the command line and execute:


mvn clean deploy -P release

Later, you will be asked to enter the password of the GPG keystore to complete the upload. The specific time depends on the network conditions. Of course, sometimes do not pop up input password box, just prompt need to enter the password, according to the GPG plug-in's official website explanation (http://maven.apache.org/plugins/maven-gpg-plugin/usage.html), need to add the password as a parameter to execute the command, namely:

MVN clean deploy-P release-dgpg. passphrase = Password
7. Publish components in Oss

After building and uploading, you need to confirm the operation in the OSS system, publish the component, and enter repositories ". Click, enter your groupid in the search box on the right to quickly locate the component, you can find that your component Status is "open". Check your component to view the verification result, if there are no errors, click the "close" button on the right side of the checkbox you just selected. In the pop-up box, "Confirm" needs to be verified again. The results will be notified by email later.

After Successful Logon (the system runs automatically and quickly), log on to the system again and find your component. The status is "closed". Check the component again, click "release" next to "close" and then "Confirm" in the pop-up box. The results will be notified by email later.

8. Notify sonatype's staff to disable issue

Return to the issue system, find your issue applying for publishing the component, and resume the team below, indicating that the component has been released. After confirmation by the staff, the issue will be closed.

9. components used

After everything is done, you cannot use the published issue immediately. You must wait for the system to synchronize your components to the central warehouse before using it. This takes at least two hours, then you can find your component on the central repository search page (http://search.maven.org,

Hurry up and show off to others.

10. Special Instructions

Is the above system very complicated? Don't worry, this is only the first time you use your groupid to publish a component. It has been proved by practice that after the first success, you can use your groupid to publish any component, you only need your groupid to remain unchanged. (Of course you cannot release duplicate components.

Subsequent release process:

A) after the component is ready, upload and build the component on the command line;

B) In the https://oss.sonatype.org/"close" and "release" component;

C) after the synchronization is completed (about 2 hours), you can use it.




Release Maven components to the central repository

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.