如何将jar包上传到Maven中央仓库

最近actable的部分功能已经完善了,一些小伙伴已经在使用了,但是由于没有放到远程仓库,导致使用的小伙伴都需要自己将代码取下来,然后install,这样不太好,所以最近就规划了下包结构,上传到了maven中央仓库中,以下是上传步骤。

1.创建工单

1.1 https://issues.sonatype.org/secure/Dashboard.jspa新建一个账号,登录后选择Create Issue,
选择Community Support - Open Source Project Repository Hosting (OSSRH)以及New Project,
其他按照你自己的项目情况填写。 

如何将jar包上传到Maven中央仓库_第1张图片
2.等待回复

2.1 发布完后几小时内会有工作人员问你是否有Group Id对应的那个域名的所有权,如果有的话就回复有,
然后就会得到Configuration has been prepared的回复,这个时候就可以准备发布了。
如果自己没有域名的话可以挂在开源的域名下面,例如com.gitee.sunchenbin,这样一样可以发布。

2.2 下面是我的项目的几次回复,最终状态变为Resolved的时候表示你有权限可以上传东西了。

如何将jar包上传到Maven中央仓库_第2张图片

3.使用gpg生成密钥

 3.1我这里使用的是windows,直接用的Git Gui的git-bash.exe如下
$ gpg --gen-key
gpg (GnuPG) 1.4.21; Copyright (C) 2015 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please 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?
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) "

Real name: sunchenbin
Email address: sunchenbinkey@163.com
Comment:
You selected this USER-ID:
    "sunchenbin "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
You need a Passphrase to protect your secret key.

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
......+++++
.....+++++
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
........+++++
+++++
gpg: key 09D71290 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
pub   2048R/09D71290 2017-11-13
      Key fingerprint = 6A67 3904 E8BB F8D6 780B  CC5D 65E4 DAD5 09D7 1290
uid                  sunchenbin 163.com>
sub   2048R/23D05BFD 2017-11-13
这样密钥就产生了,You need a Passphrase to protect your secret key.
注意这里输入的密码,后续上传到maven中央仓库是需要用到的。

3.2 上传密钥

首先查看自己key的编号:
gpg --list-keys

找到 pub对应的那个编号,例如pub 2048R/8C473F5C 
上传到key验证库:
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 8C473F5C

4.配置pom.xml

4.1 pom中增加如下的配置就好   
    <parent>
        <groupId>org.sonatype.ossgroupId>
        <artifactId>oss-parentartifactId>
        <version>7version>
    parent>

    <name>com.gitee.sunchenbin.mybatis.actable:mybatis-enhance-actablename>
    <description>A.CTable is a Maven project based on Spring and Mybatis, which enhances the function of Mybatisdescription>
    <url>https://gitee.com/sunchenbin/mybatis-enhanceurl>

    <licenses>
       <license>
          <name>The Apache Software License, Version 2.0name>
          <url>http://www.apache.org/licenses/LICENSE-2.0.txturl>
          <distribution>actabledistribution>
       license>
    licenses>

    <developers>
        <developer>
            <name>sunchenbinname>
            <email>[email protected]email>
            <organization>sunchenbinorganization>
            <url>https://gitee.com/sunchenbin/mybatis-enhanceurl>
        developer>
    developers>

    <scm>
        <connection>scm:git:[email protected]:sunchenbin/mybatis-enhance.gitconnection>
        <developerConnection>scm:git:[email protected]:sunchenbin/mybatis-enhance.gitdeveloperConnection>
        <url>https://gitee.com/sunchenbin/mybatis-enhanceurl>
        <tag>1.0tag>
    scm>
    <distributionManagement>
        <snapshotRepository>
           
          <id>ossid>
          <name>OSS Snapshots Repositoryname>
           
          <url>https://oss.sonatype.org/content/repositories/snapshots/url>  
        snapshotRepository>
        <repository>
          <id>ossid>
          <name>OSS Staging Repositoryname>
           
          <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/url>
        repository>
      distributionManagement>
4.2 配置Maven的settings.xml 
<servers>
  <server>
    <id>sonatype-nexus-snapshotsid>
    <username>上面第一步时注册的帐号username>
    <password>上面第一步时注册的密码password>
  server>
  <server>
    <id>sonatype-nexus-stagingid>
    <username>上面第一步时注册的帐号username>
    <password>上面第一步时注册的密码password>
  server>
servers>

5.部署上传jar包

命令行进入到项目pom.xml所在的目录下,运行如下命令:
mvn clean deploy -P sonatype-oss-release -Darguments="gpg.passphrase=
设置gpg设置密钥时候输入的Passphrase"
过程中可能需要你手动输入密码。

6.release jar包

如果前几个步骤全部正确完成,登录https://oss.sonatype.org/#stagingRepositories
(用户名密码就是第一步注册时的用户名密码),将Staging Rpositories拉到最下即可看到你刚刚发布的jar包,
选择上方的Close,稍等片刻他先检查一下你上传的东西是否符合规范,检查完毕后该条状态被标记为closed,
此时选中后点上面的Release即可,等2个小时左右即可在http://search.maven.org/看到你发布的jar包。

你可能感兴趣的:(Maven,漫漫编程路)