1. 首页

这篇文章教会你把个人开发的jar包发布到maven中央仓库

作者:小傅哥
博客:https://bugstack.cn原创系列专题案例

沉淀、分享、成长,让自己和他人都能有所收获!😄

前言介绍

(19年12月)最近想基于Spring Boot做个开源共享项目,开发一个分布式任务DcsSchedule中间件可以把Schedule增强。那么遇到一个问题希望把Jar包发包到Maven中央仓库,这样需要使用的用户就可以直接引入。

发布准备

内容

备注

1

申请Github帐号: https://github.com

用于上传开源代码:https://github.com/fuzhengwei…

2

GPG生成密钥工具: https://gpg4win.org/download….

在后续流程中下载安装生成密钥并上传置服务器,本文使用的服务器是:hkp://keyserver.ubuntu.com:80

3

工单系统: https://issues.sonatype.org

负责申请上传资格及完成第一次上传,后续更新不需要使用,相当于一个启动装置

4

构件仓库: https://oss.sonatype.org

上传的jar包会先存放到这里,在这里进行 Release 后即可发布到maven中央仓库,也可以本地设置自动发布

5

镜像仓库: http://search.maven.org

最终成功发布的jar可以在这里搜到

6

Maven仓库:https://mvnrepository.com

经过几个小时耐心的等待会在Maven仓库中搜到

7

阿里云仓库:https://maven.aliyun.com

阿里云的仓库会同步的快一些

8

个人域名:https://bugstack.cn

这里主要用于工单资格验证(Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53637 (Fastest))

跟着节奏

1. 下载安装Gpg生成密钥

我们需要一个GPG环境,用来对上传的文件进行加密和签名,保证你的jar包不被篡改

1991年,程序员Phil Zimmermann为了避开政府监视,开发了加密软件PGP。这个软件非常好用,迅速流传开来,成了许多程序员的必备工具。但是,它是商业软件,不能自由使用。所以,自由软件基金会决定,开发一个PGP的替代品,取名为GnuPG。这就是GPG的由来。

  1. 下载地址:https://gpg4win.org/download.html
  2. 下载完成后直接安装即可,比较傻瓜式安装很简单,记得选中文(如果你英文硬也可以不选)
  3. 生成密钥(可以使用命令行生成,也可以直接在操作界面生成)
    1. 文件>新建密钥对(Ctrl+N) — 创建个人 OpenPGP 密钥对
  4. 填写个人信息姓名和邮箱 并点击到 新建

  5. 填写密钥密码

  6. 将公钥上传到目录服务{如果上传失败,则通过:设置(S)->配置Kleopatra(C),修改 OpenPGP密钥服务器为:hkp://keyserver.ubuntu.com:80}

2. 工单系统帐号注册issues.sonatype

1. 注册地址:https://issues.sonatype.org/s…

2. 创建工单

  • 项目:Community Support – Open Source Project Repository Hosting
  • 概要:发布Jar的名称
  • 描述:非必填,最好描述清晰
  • Group Id:org.itatack.middleware & 和你的域名有关系,因为后续需要使用域名验证
  • Project URL:Github项目站点(https://github.com/fuzhengwei…
  • SCM url:源码仓库(https://github.com/fuzhengwei…

3. 配合人工审核

  1. 当创建完工单后,会收到信息反馈(国外与我们有时间差,半夜的时候他们审核的更快);



java
Do you own the domain itstack.org? If so, please verify ownership via one of the following methods:

Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53637 (Fastest)
Setup a redirect to your Github page (if it does not already exist)
If you do not own this domain, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html
You may also choose a groupId that reflects your project hosting, in this case, something like io.github.fuzhengwei or com.github.fuzhengwei

Would you like to use a free managed security reporting service (recommended)?
Put https://hackerone.com/central-security-project/reports/new as your project's security issue reporting URL. We'll take care of the rest.
For more details on the Central Security Project, visit https://www.sonatype.com/central-security-project

![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91c2VyLWdvbGQtY2RuLnhpdHUuaW8vMjAxOS8xMi83LzE2ZWRmMGI3ZmZjYTAzZWM?x-oss-process=image/format,png)
  1. 配置域名验证签名;TXT 指向问题域:https://issues.sonatype.org/b…

![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91c2VyLWdvbGQtY2RuLnhpdHUuaW8vMjAxOS8xMi83LzE2ZWRmMGI3ODc5YjIzNGQ?x-oss-process=image/format,png)
  1. 在域名验证截图,回复到问题下,人工审核会进行验证处理

![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91c2VyLWdvbGQtY2RuLnhpdHUuaW8vMjAxOS8xMi83LzE2ZWRmMGI4MGI0NTFjOWU?x-oss-process=image/format,png)
  1. 验证成功后,会收到邮件回复,也可以在issues看到{意思就说去发布你的Jar吧宝贝,发布完告诉我一下(来这里回复下,我就让你用了)}

org.itstack.middleware has been prepared, now user(s) fuzhengwei can: * Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots * Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2 * Release staged artifacts into repository 'Releases'

please comment on this ticket when you promoted your first release, thanks

1. 接下来等待发布Jar包成功后,到这里回复并收到反馈,如下(证明你成功了!);
Central sync is activated for org.itstack.middleware. After you successfully release, your component will be published to Central, typically within 10 minutes, though updates to search.maven.org can take up to two hours.




### 3\. 配置Maven Settings.xml #### 1\. Maven Settings.xml 配置,在servers中添加;


sonatype-nexus-snapshots
https://issues.sonatype.org的账号 https://issues.sonatype.org的密码


sonatype-nexus-staging
https://issues.sonatype.org的账号 https://issues.sonatype.org的密码


ossrh
https://issues.sonatype.org的账号 https://issues.sonatype.org的密码


#### 2\. 为了更快的加载Jar,在mirrors中配置了阿里云仓库;


alimavenrepository
aliyun maven repository
http://maven.aliyun.com/nexus/content/groups/public/
central


#### 3\. 密钥配置,在profile中添加ossrh
ossrh

true
<gpg.executable>D:/Program Files (x86)/GnuPG/bin/gpg.exe</gpg.executable>
<gpg.passphrase>上面生成的密钥密码:bugstack.cn</gpg.passphrase>
<gpg.homedir>{找到dir:cmd->gpg –list-key}C:/Users/fuzhengwei/AppData/Roaming/gnupg</gpg.homedir>

### 4\. 配置POM文件 #### 1\. 在pom文件里添加scm、licenses、developers、distributionManagement
The Apache Software License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.txt
repo


https://github.com/fuzhengwei/schedule-spring-boot-starter
https://github.com/fuzhengwei/schedule-spring-boot-starter.git
https://github.com/fuzhengwei/schedule-spring-boot-starter



fuzhengwei
184172133@qq.com
https://github.com/fuzhengwei/schedule-spring-boot-starter



ossrh
https://oss.sonatype.org/content/repositories/snapshots


#### 2\. 配置编译发布信息build,gpg相关插件 + maven-source-plugin 用来生成Source Jar文件 + maven-javadoc-plugin 用来生成 javadoc 文档 + maven-gpg-plugin 用来对工程文件进行自动签名 + nexus-staging-maven-plugin 用来将工程发布到中央仓库,另外注意生成javadoc文档时需要指定关闭doclint,不然可能因为使用了不规范的javadoc注解而导致失败,完整配置如下


org.apache.maven.plugins
maven-source-plugin
2.2.1


attach-sources

jar-no-fork


org.apache.maven.plugins
maven-javadoc-plugin
2.9.1


attach-javadocs

jar


-Xdoclint:none


org.apache.maven.plugins
maven-gpg-plugin
1.5


sign-artifacts verify
sign


org.sonatype.plugins
nexus-staging-maven-plugin
1.6.7
true

ossrh
https://oss.sonatype.org/
true
org.apache.maven.plugins
maven-release-plugin
2.4.2

> Js中文网 - 前端进阶资源教程 [www.javascriptC.com](https://www.javascriptc.com),typescript 中文文档
> 一个帮助开发者成长的社区,**你想要的,在这里都能找到**


### 4\. 执行发布;Idea Maven -> Lifecycle -> Deploy

1.  接下来开发发布Jar包,中间会提示输入密钥生成时候的密码
2.  [https://oss.sonatype.org][16] 查看发布内容
3.  到上面"配合人工审核",按照说明提交发布成功信息,验证成功后会收到回复,如下;

Central sync is activated for org.itstack.middleware. After you successfully release, your component will be published to Central, typically within 10 minutes, though updates to search.maven.org can take up to two hours.
“`

  1. https://search.maven.org 搜索版本信息
    这篇文章教会你把个人开发的jar包发布到maven中央仓库
  2. https://maven.aliyun.com 阿里云仓库同步较快,可以查看
    这篇文章教会你把个人开发的jar包发布到maven中央仓库

综上总结

  • 整体流程还是很长的,如果第一次尝试去弄,嗯,你可能有一个不眠夜
  • 中间可能会遇到各种异常错误,包括密钥、打包、发版等等,注意仔细阅读本文细节以及自己多次尝试,总归是会成功的
  • 比较常识性的问题;同一个RELEASE版本只能上传一次否则会失败、老外真的是半夜回复比较快因为咱们半夜他们正好天亮了

推荐阅读

作者:小傅哥
链接:https://segmentfault.com/a/1190000022963073

看完两件小事

如果你觉得这篇文章对你挺有启发,我想请你帮我两个小忙:

  1. 关注我们的 GitHub 博客,让我们成为长期关系
  2. 把这篇文章分享给你的朋友 / 交流群,让更多的人看到,一起进步,一起成长!
  3. 关注公众号 「画漫画的程序员」,公众号后台回复「资源」 免费领取我精心整理的前端进阶资源教程

JS中文网是中国领先的新一代开发者社区和专业的技术媒体,一个帮助开发者成长的社区,目前已经覆盖和服务了超过 300 万开发者,你每天都可以在这里找到技术世界的头条内容。欢迎热爱技术的你一起加入交流与学习,JS中文网的使命是帮助开发者用代码改变世界

本文著作权归作者所有,如若转载,请注明出处

转载请注明:文章转载自「 Js中文网 · 前端进阶资源教程 」https://www.javascriptc.com

标题:这篇文章教会你把个人开发的jar包发布到maven中央仓库

链接:https://www.javascriptc.com/4309.html

« 如何给女朋友讲解什么是Git
一起学习手写 JSON Parser»
Flutter 中文教程资源

相关推荐

QR code