Upload Android or Java library to MAVEN Central repository (reprint)

Source: Internet
Author: User
Tags gnupg gpg using git maven central sonatype sonatype nexus

This article mainly introduces the use of sonatype to submit jars or AAR to Maven's central repository .

Would you like to upload your jar or AAR to the MAVEN official repository, which can be used by other people in the central repository, then look down.

1, Sonatype Introduction
Sonatype uses Nexus to provide managed services for open source projects. You can either publish the snapshot (snapshot) or the stable version (release) to the MAVEN central repository. We just need to register a sonatype Jira account, create a Jira ticket, and then configure the Pom file slightly.

2. Registered Account
Open https://issues.sonatype.org/registered Sonatype Jira account, this account will need to be used to configure Maven server later.
Open Create a OSSRH Ticke creating a Jira ticket, one of your projects corresponds to a Jira ticket here,
Where summary can fill in the project name, description fill in the project introduction.
The group ID is very important and must be the parent of the group ID in your project pom.xml, as the tag associated with your account and the project. As my project Pom.xml group ID is Cn.trinea.android.common, for all of my projects can be published, the application to fill the group ID is cn.trinea
Others follow the prompts to fill in. After the completion of about 2 business days, the issue will become _RESOLVED_ status indication is available, the following procedure in addition to the 7th step of the formal release, the other is not a problem .

3. Software Environment
(1) JDK5 or above
(2) Subversion or Git
This is based on your project needs, what version control management tools do you use?
(3) Maven 2.2.1+
(4) GPG for encrypting and signing files that need to be uploaded
: Https://www.gnupg.org/download/index.html,windows version: http://gpg4win.org/
After the installation is complete by using the command line mode

1 GPG -- Gen - Key

command to generate your own public key, in addition to the name, mailbox, notes and other can use the default configuration, and finally need to fill out a passphase, note that it is required after MVN release signature.

Public key generation ends with

1 GPG -- List - Keys

command to view key contents as follows:

XHTML
1 2 3) 4 5 C:/Users/Trinea/AppData/Roaming/GnuPG/Pubring.Gpg--------------------------------------------------------pub2048r/c6eed57a2014-05-Uidtrinea(Www.Trinea.cn)<[email protected]>sub2048r/932d6f332014-05-11

Where c6eed57a is the key ID, it needs to be reported to the server, the command is as follows:

1 GPG--KEYSERVERHKP://pool. SKS-keyservers. NET--send-keysc6eed57a

This completes the creation and escalation operation of GPG public key.

If interested in an in-depth look at the visible: how to Generate PGP Signatures with Maven

4, the standard POM file format

(1) The Pom file must contain the following elements
<modelVersion>
<groupId>
<artifactId>
<version>
<packaging>
<name>
<description>
<url>
<licenses>
<scm><url>
<scm><connection>
<developers>

(2) If it is a jar file, it must contain-javadoc.jar and-sources.jar, that is, the appropriate plugin to configure the build in the POM

For Pom.xml content refer to: Https://github.com/Trinea/android-common/blob/master/pom.xml

Where you need to modify the following
(1) Change the relevant element information to your own project information.
(2) The parent of parent or parent must be guaranteed to be

Java
1 2 3) 4 5 <parent>     <groupId>org.Sonatype.OSS</groupId>     <artifactId>OSS-Parent</Artifactid>     <version>7</version> </Parent>

(3) If your version control is not using Git, but other tools, configure see POM and Settings config

(4) The pure Java (non-Android) project needs to change <packaging>aar</packaging> to <packaging>jar</packaging>

Java
1 2 3 4 5 6 7 <!--AndroidDeps--> <dependency>     <groupId>com.Google.Android</groupId>     <artifactId>Android</Artifactid>     <version>4.0.1.2</version>     <scope>provided</Scope> </Dependency>

And

Java
1 2 3 4 5 6 7 8 9 10 11 12 <plugin>     <groupId>com.Jayway.maven.Plugins.Android.Generation2</groupId>     <artifactId>Android-maven-plugin</Artifactid>     <version>3.8.0</version>     <configuration>         <sdk>             <platform> -</Platform>         </SDK>         <undeployBeforeDeploy>true</Undeploybeforedeploy>     </Configuration>     <extensions>true</Extensions> </plugin>

5. Configure MAVEN Warehouse Address

Add in the Settings.xml file in the. M2 Directory

Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <settings>   ...   <servers>     <server>       <id>Sonatype-Nexus-Snapshots</ID>       <username>your-Jira-ID</username>       <password>your-Jira-pwd</Password>     </Server>     <server>       <id>Sonatype-Nexus-Staging</ID>       <username>your-Jira-ID</username>       <password>your-Jira-pwd</Password>     </Server>   </Servers>   ... </Settings>

Replace the Your-jira-id and your-jira-pwd with your user name and password on the https://issues.sonatype.org/.

M2 directory under Linux path is/home/user-name/.m2,windows under path is C:\USERS\YOUR-USER-NAME\.M2

If the settings modification does not take effect in later steps, refer to: Maven sonatype Nexus return 401

6. Compile and upload

(1) Release a snapshot version
MVN Clean Deploy
Login https://oss.sonatype.org (username and password on https://issues.sonatype.org/) after publishing, and find your own artifact by steps (uploaded jar or aar or POM, etc.)

(2) Release a release version
MVN Release:clean Release:prepare Release:perform
The process needs to be signed by GPG, you need to enter the above passphase. We can still find our artifact with similar steps after the release is complete.

Other upload methods see stage a Release

7. Official release

The official release here refers to synchronizing to the MAVEN main repository so that others can use it. Mainly includes close and release two steps, first close after release, respectively, such as


Others do not understand can view: Release

Need to be aware

(1) may appear at release

XHTML
1 2 releasefailed nexusreturnedanerror:ERROR403:Forbidden

403 pop-up windows, which may be due to the Jira ticket created in 2, the status has not changed to _resolved_, waiting to be available. If the value of the profile column in your repository list above is not the group ID that you created Jira ticket, you need to resubmit it.

(2) If it is the first release, need to before your Jira ticket, under the comments told them that you have been release, need to sync, my Jira ticket:ossrh-9800. Such as:

Official guide: Sonatype OSS Maven Repository Usage Guides

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.