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

来源:互联网 发布:温柔知乎 编辑:程序博客网 时间:2024/03/28 20:32

最近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,其他按照你自己的项目情况填写。 

这里写图片描述
2.等待回复

2.1 发布完后几小时内会有工作人员问你是否有Group Id对应的那个域名的所有权,如果有的话就回复有,然后就会得到Configuration has been prepared的回复,这个时候就可以准备发布了。如果自己没有域名的话可以挂在开源的域名下面,例如com.gitee.sunchenbin,这样一样可以发布。2.2 下面是我的项目的几次回复,最终状态变为Resolved的时候表示你有权限可以上传东西了。

这里写图片描述

3.使用gpg生成密钥

 3.1我这里使用的是windows,直接用的Git Gui的git-bash.exe如下
$ gpg --gen-keygpg (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 bitsPlease 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 yearsKey is valid for? (0)Key does not expire at allIs this correct? (y/N) yYou 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) <heinrichh@duesseldorf.de>"Real name: sunchenbinEmail address: sunchenbinkey@163.comComment:You selected this USER-ID:    "sunchenbin <sunchenbinkey@163.com>"Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? oYou need a Passphrase to protect your secret key.We need to generate a lot of random bytes. It is a good idea to performsome 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 performsome 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 trustedpublic and secret key created and signed.gpg: checking the trustdbgpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust modelgpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2upub   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找到 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.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>458757617@qq.com</email>            <organization>sunchenbin</organization>            <url>https://gitee.com/sunchenbin/mybatis-enhance</url>        </developer>    </developers>    <scm>        <connection>scm:git:git@gitee.com:sunchenbin/mybatis-enhance.git</connection>        <developerConnection>scm:git:git@gitee.com:sunchenbin/mybatis-enhance.git</developerConnection>        <url>https://gitee.com/sunchenbin/mybatis-enhance</url>        <tag>1.0</tag>    </scm>    <distributionManagement>        <snapshotRepository>          <!-- 这个id需要在setting.xml中设置  -->           <id>oss</id>          <name>OSS Snapshots Repository</name>          <!-- 这里的url就是Issue中回复的snapshots 的repo地址-->           <url>https://oss.sonatype.org/content/repositories/snapshots/</url>          </snapshotRepository>        <repository>          <id>oss</id>          <name>OSS Staging Repository</name>          <!-- 这里的url就是Issue中回复的staging 的repo地址-->           <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=设置gpg设置密钥时候输入的Passphrase"
过程中可能需要你手动输入密码。

6.release jar包

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