1.github上上传项目(略)
2.在sonatype上注册账号
https://issues.sonatype.org/secure/Dashboard.jspa
注意记住用户名和密码
3.在sonatype创建问题
4.新建完后客服会给提示
主要是要求:groupId要合理,需要按照要求在github上创建空仓库,做完这些后,然后修改状态为打开即可。
5.审核成功后会发邮件通知,状态显示为已解决
6.项目修改groupId为上方指定的groupId
7.修改maven的setting.xml配置
<servers> <server> <id>ossrhid> <username>sonatype用户名username> <password>sonatype登录密码password> server> servers>
8.修改pom.xml配置
<distributionManagement> <snapshotRepository> <id>ossrhid> <url>https://s01.oss.sonatype.org/content/repositories/snapshotsurl> snapshotRepository> <repository> <id>ossrhid> <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/url> repository> distributionManagement>
- 打包上传
mvn clean install
mvn deploy
10.在仓库上查看快照版的jar包是否上传成功
打开:https://s01.oss.sonatype.org/
11.发布正式版
批量修改版本号:
mvn versions:set -DnewVersion=1.0.0
部署:
mvn clean deploy
12.在sonatype上查看暂存版
13.解决问题后放开进一步发布到正式版
主要要解决文件签名问题,给文件生成签名文件
下载gpg4win:https://www.gpg4win.org/download.html
安装后,生成证书,发布到服务器等
参考:https://blog.csdn.net/ooyyaa6561/article/details/124900977
14.gpg相关配置
setting.xml配置
<profile> <id>ossrhid> <activation> <activeByDefault>trueactiveByDefault> activation> <properties> <gpg.executable>gpggpg.executable> <gpg.passphrase>密码gpg.passphrase> properties> profile>
pom.xml配置
<profiles> <profile> <id>releaseid> <build> <plugins> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-source-pluginartifactId> <version>2.2.1version> <executions> <execution> <id>attach-sourcesid> <goals> <goal>jar-no-forkgoal> goals> execution> executions> plugin> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-javadoc-pluginartifactId> <version>2.9.1version> <executions> <execution> <id>attach-javadocsid> <goals> <goal>jargoal> goals> execution> executions> plugin> <plugin> <groupId>org.apache.maven.pluginsgroupId> <artifactId>maven-gpg-pluginartifactId> <version>3.0.1version> <executions> <execution> <id>sign-artifactsid> <phase>verifyphase> <goals> <goal>signgoal> goals> execution> executions> plugin> plugins> build> profile> profiles>
- 运行打包部署命令
指定release这个profile运行
打包
mvn clean install -P release
部署
mvn clean deploy -P release
- 及时发布
close后,会给问题反馈,没问题后,点击Release
17.jar包拉取验证
sonatype仓库验证:在pom.xml中添加仓库
<repository> <id>nexuesid> <name>snapshotsname> <url>https://s01.oss.sonatype.org/content/groups/public/url> <releases> <enabled>trueenabled> releases> <snapshots> <enabled>trueenabled> <updatePolicy>alwaysupdatePolicy> snapshots> repository>
然后添加maven依赖配置
快照版和正式版均可以下载,正式版优先级高!
maven中央仓库验证:
setting.xml文件无需配置,默认就可以直连maven中央仓库,直接引入依赖即可
<dependency> <groupId>io.github.hdwang123groupId> <artifactId>openapi-server-sdkartifactId> <version>1.0.0version> dependency> <dependency> <groupId>io.github.hdwang123groupId> <artifactId>openapi-client-sdkartifactId> <version>1.0.0version> dependency>
经过大约4个小时终于收到成功的邮件,验证果然成功了,下面是邮件截图
遇到的问题:
gpg插件无法运行
解决:1.安装完gpg4win后需要重启电脑,切记 2. setting.xml中的命令可能是gpg而非gpg2
Original: https://www.cnblogs.com/hdwang/p/16318620.html
Author: 追极
Title: 第一次发布jar包到maven中央仓库
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/587773/
转载文章受原作者版权保护。转载请注明原作者出处!