平时自己开发的工具类或者其他的框架的jar包一般都是放在本地。或者把代码上传到github让别人去下载然后自己打包。今天就说说如何把自己的jar包发布到Maven的中央仓库。让其他使用你的jar包的直接去中央仓库下载。如果你用的是阿里云的maven中央仓库。同样阿里云的中央仓库也会同步你的jar包。
1 注册JIRA账号
注册地址:https://issues.sonatype.org/secure/Dashboard.jspa
2 创建 issue
这些都是要填写的!Project URL 和SCM url 可以填写自己github项目的地址 Group ID 可以按自己需求填写,比如我填写的是com.github.mxsm 创建好以后 sonatype的工作人员审核处理,速度还是很快的,一般一个工作日以内,当Issue的Status变为RESOLVED后,就可以进行下一步操作了,否则,就等待… (国内最好你在晚上干这个事情国外刚好上班)
到了这里说明你已经能够去上传自己的jar包了
3 配置maven Setting.xml文件
添加Server节点
<server><id>自行替换</id><username>替换成自己的JIRA账号</username><password>替换成自己的JIRA账号密码</password></server>
4 创建maven工程
设置pom.xml文件
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.github.mxsm</groupId><artifactId>dubbotest</artifactId><version>1.0</version><packaging>jar</packaging><name>dubbotest</name><url>https://github.com/mxsm</url><description>dubbotestcom.github.mxsmjar</description><licenses><license><name>Apache2</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url><distribution>repo</distribution><comments>Abusiness-friendlyOSSlicense</comments></license></licenses><scm><url>https://github.com/mxsm</url><connection>https://github.com/mxsm/taokeeper.git</connection></scm><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.10.RELEASE</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.5.3</version></dependency></dependencies><developers><developer><name>ljbmxsm</name><id>ljbmxsm</id><email>ljbmxsm@gmail.com</email><roles><role>Developer</role></roles><timezone>+8</timezone></developer></developers><profiles><profile><id>release</id><!--部署要用到--><build><plugins><!--Source--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>2.2.1</version><executions><execution><phase>package</phase><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><!--Javadoc--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version><executions><execution><phase>package</phase><goals><goal>jar</goal></goals></execution></executions></plugin><!--GPG--><plugin><!--进行延签--><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.6</version><executions><execution><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin></plugins></build><distributionManagement><snapshotRepository><id>oss</id><url>https://oss.sonatype.org/content/repositories/snapshots/</url></snapshotRepository><repository><id>oss</id><url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement></profile></profiles></project>
必须要的:name url description licenses scm
<distributionManagement><snapshotRepository><id>oss</id><!--settings.xml中server节点的id--><url>https://oss.sonatype.org/content/repositories/snapshots/</url></snapshotRepository><repository><id>oss</id><url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement>
5 windows环境安装gpg4win
下载地址:https://www.gpg4win.org/download.html
查看版本:
$gpg--gen-keygpg(GnuPG)1.4.19;Copyright(C)2015FreeSoftwareFoundation,Inc.Thisisfreesoftware:youarefreetochangeandredistributeit.ThereisNOWARRANTY,totheextentpermittedbylaw.Pleaseselectwhatkindofkeyyouwant:(1)RSAandRSA(default)(2)DSAandElgamal(3)DSA(signonly)(4)RSA(signonly)Yourselection?RSAkeysmaybebetween1024and4096bitslong.Whatkeysizedoyouwant?(2048)Requestedkeysizeis2048bitsPleasespecifyhowlongthekeyshouldbevalid.0=keydoesnotexpire<n>=keyexpiresinndays<n>w=keyexpiresinnweeks<n>m=keyexpiresinnmonths<n>y=keyexpiresinnyearsKeyisvalidfor?(0)KeydoesnotexpireatallIsthiscorrect?(y/N)YYouneedauserIDtoidentifyyourkey;thesoftwareconstructstheuserIDfromtheRealName,CommentandEmailAddressinthisform:"HeinrichHeine(DerDichter)<heinrichh@duesseldorf.de>"Realname:ljbmxsmEmailaddress:ljbmxsm@gmail.comComment:flink-elasticsearch-connectorYouselectedthisUSER-ID:"iteblog(flink-elasticsearch-connector)<wyphao.2007@163.com>"Change(N)ame,(C)omment,(E)mailor(O)kay/(Q)uit?OYouneedaPassphrasetoprotectyoursecretkey.Weneedtogeneratealotofrandombytes.Itisagoodideatoperformsomeotheraction(typeonthekeyboard,movethemouse,utilizethedisks)duringtheprimegeneration;thisgivestherandomnumbergeneratorabetterchancetogainenoughentropy.+++++.+++++gpg:/c/Users/iteblog/.gnupg/trustdb.gpg:trustdbcreatedgpg:keyB15C5AA3markedasultimatelytrustedpublicandsecretkeycreatedandsigned.
设置名字+邮箱,其他可以使用默认值,记住输入的passphrase,后面部署会用到
6 上传密钥
上传刚刚生成的秘钥
上传命令
gpg--keyserverhkp://keyserver.ubuntu.com:11371--send-keysCF21873A--上传到服务器gpg--keyserverhkp://keyserver.ubuntu.com:11371--recv-keysCF21873A--查看是否上传整个
http://pool.sks-keyservers.net
http://keys.openpgp.org
http://keyserver.ubuntu.com
主要:keyserver.ubuntu.com:11371 现在这个是可用的,之前网上的pool.sks-keyservers.net 反正我上传成功但是在后面验证的时候不是用的这个地址。执行部署
mvncleandeploy-Prelease
后面的release参数是 <id>release</id> <!-- 部署要用到 -->
这个. 如果在Centos8上面报
签名失败。 这说明你安装的gpg版本较新,需要额外配置,在gpg的.gnupg下建立两个配置文件:gpg.conf、gpg-agent.conf,
然后在gpg.conf添加:
use-agentpinentry-modeloopback
在gpg-agent.conf下添加:
allow-loopback-pinentry
7 登录网站查看
地址:https://oss.sonatype.org 用户名密码就是上面注册的。
查看自己的(你定义的版本号不能带SNAPSHOT要不然看不到) a)构件准备好之后,在命令行上传构建;
b)在https://oss.sonatype.org/ “close”并“release”构件;
c)等待同步好(大约2小时多)之后,就可以使用了
8 通知管理员
去网站https://issues.sonatype.org 登录通知你的管理然后等待
然后到这里就全部完成。剩下的就是等同步到中央仓库 看看我自己随便发布的一个结果:
去中央仓库查看https://search.maven.org(中央仓库需要两个小时后)
如有问题可以联系我:ljbmxsm@gmail.com 或者qq:375808041