奇幻新游活动中心



发布自己的Jar包到Maven中央仓库

出于以下目的,我开始尝试建立自己的jar包:

为了以后解决常见问题,把对应问题的解决代码保存起来,后面可以快速完成

针对网上一些问题,而我工作上没有用到的,可以自己先写一份代码保存起来,以后再遇到可以直接使用

接下来就是解决步骤:

本地手动发布代码至maven中央仓库

与GitHub仓库的事件绑定,自动发布

本地手动发布1、创建账号登陆网站,创建一个网站,推荐使用GitHub账号的方式创建。

2、创建Namespace这个为了验证你有创建对应groupId的权限。这里推荐你创建一个组织,然后就可以申请名为io.github.的Namespace

3、GPG这个看文档似乎为了生成的jar包、源码等文件,生成一个签名,具体用途不清楚,我猜可能是为了校验吧。按照文档的步骤是:

12345678910111213# 安装gpgbrew install gpg # 验证是否安装完成gpg --version# 生成key信息,按照要求输入就行,记住输入的密码gpg --gen-key# 其中输出的结果有如下信息,要记住第二行的CA开头的字符串# pub rsa3072 2021-06-23 [SC] [expires: 2023-06-23]# CA925CD6C9E8D064FF05B4728190C4130ABA0F98# uid Central Repo Test # sub rsa3072 2021-06-23 [E] [expires: 2023-06-23]# 发布你的公钥gpg --keyserver keyserver.ubuntu.com --send-keys CA925CD6C9E8D064FF05B4728190C4130ABA0F98

4、项目的pom文件修改(1)项目的坐标要明确

1234org.github.fourthiywe-javapom1.0.0

(2)提供一些基础信息

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647iywe-javaimprove your work efficiencyhttps://github.com/iywes/iywe-java GitHub Issues https://github.com/iywes/iywe-java/issues2024 MIT License https://github.com/iywes/iywe-java/blob/main/LICENSE repo snapshots https://s01.oss.sonatype.org/content/repositories/snapshots releases https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ scm:git:https://github.com/iywes/iywe-java.git scm:git:git@github.com:iywes/iywe-java.git https://github.com/iywes/iywe-java wangjie-fourth wang jie wangjie_fourth@163.com owner developer

(3)发布的插件信息

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 org.sonatype.central central-publishing-maven-plugin 0.5.0 true central org.apache.maven.plugins maven-source-plugin 3.1.0 true attach-sources jar true true org.apache.maven.plugins maven-javadoc-plugin 3.1.0 true bundle-sources package jar 1024 UTF-8 protected true false none org.apache.maven.plugins maven-gpg-plugin 1.6 sign-artifacts verify sign ossez

(4)修改maven的setting.xml文件

1

5、发布

1mvn deploy

6、到官网确认发布登陆官网,找到你刚才发布的信息,点击Publish就可以了。

GitHub仓库自动发布上面这种方式可以在本地就可以发布了,但到GitHub仓库就有问题

参考资料:

官方文档:https://central.sonatype.org/register/central-portal/