0


【拥抱开源】发布自己的项目到maven中央仓库

文章目录

🎈第一步,注册账号

官网注册账号地址

username不能是中文,不让后面会出问题

在这里插入图片描述
在这里插入图片描述

💿第二步,登录

在这里插入图片描述

📀第三步,设置信息

在这里插入图片描述
在这里插入图片描述

💾第四步,创建问题

在这里插入图片描述
在这里插入图片描述

一定要选如图的选项

在这里插入图片描述

图4.1

图4.1

概要:填你的项目名
groupid:如果gitee上的项目就填

io.gitee+下图所示antopen

,如果是公司(有域名和公司邮箱),就填

com.公司名称

在这里插入图片描述
project url:项目地址

在这里插入图片描述
SCM url:项目克隆地址(后面以.git结尾)

在这里插入图片描述

其他的如

图4.1

所示

📹第五步,验证信息

在这里插入图片描述

意思是说让你创建一个空仓库来验证是不是你本人在操作

在这里插入图片描述

创建即可,要设置为开源,gitee现在默认是私有的

在这里插入图片描述

创建完成之后点击Respond按钮告诉工作人员已经创建好了

**我这里已经成功了,所以没有

Respond

按钮**

在这里插入图片描述

🎥第六步,上传jar包到中央仓库

在这里插入图片描述

💻我们先上传snapshot版本的

📺第一步,配置密钥
📱第一步,下载密钥生成器

下载并安装GPG:
https://www.gnupg.org/download/index.html

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

☎️第二步,生成密钥

在这里插入图片描述

进入bin目录

在这里插入图片描述

gpg --gen-key

依次输入姓名和地址,填你注册sonatype的信息就行了

在这里插入图片描述

然后让你输入密码(私钥密码

passphrase

记住,后面要用

在这里插入图片描述


pub   ed25519 2023-01-09[SC][expires:2025-01-08]A4BE13B592B3B38A442170A922D74586719B2B26
uid                      tset <setset@sdf。com>
sub   cv25519 2023-01-09[E][expires:2025-01-08]
A4BE13B592B3B38A442170A922D74586719B2B26

就是你的密钥,记住

☎️第三步,查看公钥
gpg --list-keys

在这里插入图片描述

存储路径,记住

📞第四步,发布公钥
gpg --keyserver hkp://keyserver.ubuntu.com:11371--send-keys A4BE13B592B3B38A442170A922D74586719B2B26

意思就是上传到

hkp://keyserver.ubuntu.com:11371

中去,然后sonatype也会去这里验证

查询发布公钥是否成功


gpg --keyserver hkp://keyserver.ubuntu.com:11371--recv-keys A4BE13B592B3B38A442170A922D74586719B2B26

出现这样就成功了

在这里插入图片描述

📟第二步,配置maven
📠第一步,配置maven的settings.xml文件
<servers><server><id>ossrh</id><username>(SonaType账号username)</username><password>填你注册SonaType时填写的密码</password></server></servers><profiles><profile><id>ossrh</id><activation><activeByDefault>true</activeByDefault></activation><properties><!--这里填你安装的GnuPG位置--><gpg.executable>D:/gpg/GnuPG/bin/gpg.exe</gpg.executable><gpg.passphrase>填写你生成秘钥时输入的密码</gpg.passphrase><!--这里填你秘钥在磁盘上的位置,可通过上面步骤的 gpg --list-keys找到--><gpg.homedir>C:/Users/Administrator/AppData/Roaming/gnupg</gpg.homedir></properties></profile></profiles>
💽第二步,idea使用改配置文件

在这里插入图片描述

📼第三步,配置项目的pom文件
🔉第一步,修改配置
<!--gav信息--><groupId>io.gitee.antopen</groupId><artifactId>simple-cache</artifactId><!--需要特别注意,你上传的是SNAPSHOT仓库,所以此处版本号后缀必须带SNAPSHOT--><version>1.0.0-SNAPSHOT</version><!--项目信息...--><name>simple-cache</name><description>simple cache</description><url>https://gitee.com/antopen/simple-cache</url><!--开源协议...--><licenses><license><name>The Apache Software License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url></license></licenses><!--开发者信息--><developers><developer><id>masiyi</id><name>masiyi</name><email>[email protected]</email><roles><role>Project Manager</role><role>Architect</role></roles><timezone>+8</timezone></developer></developers><!--项目在github或其它托管平台的地址--><scm><connection>https://gitee.com/antopen/simple-cache.git</connection><developerConnection>scm:git:ssh://[email protected]:antopen/simple-cache.git</developerConnection><url>https://gitee.com/antopen/simple-cache</url></scm><profiles><profile><!--注意,此id必须与setting.xml中指定的一致,不要自作聪明改它名字--><id>ossrh</id><activation><activeByDefault>true</activeByDefault></activation><build><!--发布到中央SNAPSHOT仓库插件--><plugins><plugin><groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>1.6.7</version><extensions>true</extensions><configuration><serverId>ossrh</serverId><nexusUrl>https://s01.oss.sonatype.org/</nexusUrl><autoReleaseAfterClose>true</autoReleaseAfterClose></configuration></plugin><!--生成源码插件--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>2.2.1</version><executions><execution><id>attach-sources</id><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><!--生成API文档插件--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions></plugin><!--gpg插件--><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.5</version><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin></plugins></build><distributionManagement><snapshotRepository><!--注意,此id必须与setting.xml中指定的一致--><id>ossrh</id><url>https://s01.oss.sonatype.org/content/repositories/snapshots</url></snapshotRepository><repository><id>ossrh</id><url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement></profile></profiles>
🔈 第二步,打包上传

先把上面的注释全部删掉,再上传

在这里插入图片描述

然后会弹出对话框让你输入生成gpg时填写的密码

🔇第四步,查看是否上传成功

https://s01.oss.sonatype.org/

在这里插入图片描述

能找到就是成功了

在这里插入图片描述

📢再上传release版本

📣第一步,修改settings.xml
<!--将原来server标签和profile标签中的的ossrh替换为release--><id>release</id>
⌛️第二步,修改pom文件
<groupId>io.gitee.antopen</groupId><artifactId>simple-cache</artifactId>
    去除-SNAPSHOT后缀
    <version>1.0.1</version><!--将原来profile标签中的的ossrh替换为release--><id>release</id><!--移除此发布到中央SNAPSHOT仓库插件,并替换为分割线下面发布到中央release仓库的插件--><plugin><groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>1.6.7</version><extensions>true</extensions><configuration><serverId>ossrh</serverId><nexusUrl>https://s01.oss.sonatype.org/</nexusUrl><autoReleaseAfterClose>true</autoReleaseAfterClose></configuration></plugin><!--                    分割线                --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-release-plugin</artifactId><version>2.5.3</version><configuration><autoVersionSubmodules>true</autoVersionSubmodules><useReleaseProfile>false</useReleaseProfile><releaseProfiles>release</releaseProfiles><goals>deploy</goals></configuration></plugin>
    
移除
                 <repository><id>ossrh</id><url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository>
替换为
                 <repository><id>release</id><url>https://s01.oss.sonatype.org/content/repositories/releases/</url></repository>
⏳第三步,打包上传

在这里插入图片描述

⏰第四步,查看是否上传成功

https://s01.oss.sonatype.org/

在这里插入图片描述

都上传成功之后就会收到官方的信息

在这里插入图片描述
意思是

io.gitee.antopen的中央同步已激活。成功发布后,您的组件将在中央对公众开放https://repo1.maven.org/maven2/,通常在30分钟内,但更新到https://search.maven.org可能需要四个小时。

30分钟后就可以下载,4个小时后就可以在mvn搜索网页可以搜索到

在这里插入图片描述

⌚️第七步,后续发布新版本

发布出去就改不了了,如果需要bug修复或者版本更新就只需要上传release版本即可

修改版本号,重复上面操作即可

在这里插入图片描述

鸣谢:https://blog.csdn.net/lovexiaotaozi/article/details/121989407

希望更多的小伙伴能够参与到开源当中去,这样大家才能进步,社会才会发展

标签: sonatype maven jar

本文转载自: https://blog.csdn.net/csdnerM/article/details/128610930
版权归原作者 掉头发的王富贵 所有, 如有侵权,请联系我们删除。

“【拥抱开源】发布自己的项目到maven中央仓库”的评论:

还没有评论