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

640?wxfrom=5&wx_lazy=1

来源 :csdn | 作者 : 孙琛斌|原文:阅读原文

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

640?wxfrom=5&wx_lazy=1

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

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

640

3.使用gpg生成密钥
 3.1我这里使用的是windows,直接用的Git Gui的git-bash.exe如下
$ gpg 
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
     <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 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 IDfrom the Real Name, Comment and Email Address in this form:
   "Heinrich Heine (Der Dichter) <[email protected]>"Real name: sunchenbin
Email address: sunchenbinkey@163.com
Comment:
You selected this USER-ID:
   "sunchenbin <[email protected]>"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 thedisks) during the prime generation; this gives the random numbergenerator 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 thedisks) during the prime generation; this gives the random numbergenerator 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 1290uid                  sunchenbin <sunchenbinkey@163.com>
sub   2048R/23D05BFD 2017-11-13
这样密钥就产生了,You need a Passphrase to protect your secret key.
注意这里输入的密码,后续上传到maven中央仓库是需要用到的。3.2 上传密钥首先查看自己key的编号:
gpg --list-keys
4.配置pom.xml
4.1 pom中增加如下的配置就好   
  
<parent>
       <groupId>org.sonatype.oss</groupId>
       <artifactId>oss-parent</artifactId>
       <version>7</version>
   </parent>

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

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

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

   <scm>
       <connection>scm:git:[email protected]:sunchenbin/mybatis-enhance.git</connection>
       <developerConnection>scm:git:[email protected]:sunchenbin/mybatis-enhance.git</developerConnection>
       <url>https://gitee.com/sunchenbin/mybatis-enhance</url>
       <tag>1.0</tag>
   </scm>
   <distributionManagement>
       <snapshotRepository>
         
         <id>oss</id>
         <name>OSS Snapshots Repository</name>
         
         <url>https://oss.sonatype.org/content/repositories/snapshots/</url>  
       </snapshotRepository>
       <repository>
         <id>oss</id>
         <name>OSS Staging Repository</name>
         
         <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
       </repository>
     </distributionManagement>
4.2 配置Maven的settings.xml 
<servers>
 <server>
   <id>sonatype-nexus-snapshots</id>
   <username>上面第一步时注册的帐号</username>
   <password>上面第一步时注册的密码</password>
 </server>
 <server>
   <id>sonatype-nexus-staging</id>
   <username>上面第一步时注册的帐号</username>
   <password>上面第一步时注册的密码</password>
 </server>
</servers>
5.部署上传jar包
命令行进入到项目pom.xml所在的目录下,运行如下命令:
mvn clean deploy -P sonatype-oss-release -Darguments="gpg.passphrase=
过程中可能需要你手动输入密码。
6.release jar包
如果前几个步骤全部正确完成,登录https://oss.sonatype.org/#stagingRepositories
(用户名密码就是第一步注册时的用户名密码),将Staging Rpositories拉到最下即可看到你刚刚发布的jar包,
选择上方的Close,稍等片刻他先检查一下你上传的东西是否符合规范,检查完毕后该条状态被标记为closed,
此时选中后点上面的Release即可,等2个小时左右即可在http://search.maven.org/看到你发布的jar包。
推荐阅读
【重要】公众号送书&【星球福利】
Java工程师成神之路(2018修订版)

640

猜你喜欢

转载自blog.csdn.net/b644rofp20z37485o35m/article/details/80045506