第一次发布jar包到maven中央仓库

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>ossrh</id>
  <username>sonatype用户名</username>
  <password>sonatype登录密码</password>
 </server>
</servers>

 

8.修改pom.xml配置

复制代码
 <!-- 部署配置 -->
    <distributionManagement>
        <snapshotRepository>
            <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>
复制代码

 

9. 打包上传

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>ossrh</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gpg.executable>gpg</gpg.executable>
        <gpg.passphrase>密码</gpg.passphrase>
      </properties>
    </profile>
复制代码

pom.xml配置

复制代码
<profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <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>
                    <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>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
复制代码

 

15. 运行打包部署命令

指定release这个profile运行

打包

mvn clean install -P release

部署

mvn clean deploy -P release

 

16. 及时发布

 

 close后,会给问题反馈,没问题后,点击Release

 

17.jar包拉取验证

sonatype仓库验证:在pom.xml中添加仓库

复制代码
    <repository>
            <id>nexues</id>
            <name>snapshots</name>
            <url>https://s01.oss.sonatype.org/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
复制代码

然后添加maven依赖配置

 快照版和正式版均可以下载,正式版优先级高!

 

maven中央仓库验证:

setting.xml文件无需配置,默认就可以直连maven中央仓库,直接引入依赖即可

复制代码
     <!-- openapi服务端sdk -->
        <dependency>
            <groupId>io.github.hdwang123</groupId>
            <artifactId>openapi-server-sdk</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!-- openapi客户端sdk -->
        <dependency>
            <groupId>io.github.hdwang123</groupId>
            <artifactId>openapi-client-sdk</artifactId>
            <version>1.0.0</version>
        </dependency>           
复制代码

经过大约4个小时终于收到成功的邮件,验证果然成功了,下面是邮件截图

 

 

 

遇到的问题:

gpg插件无法运行

解决:1.安装完gpg4win后需要重启电脑,切记  2. setting.xml中的命令可能是gpg而非gpg2

 

posted @   追极  阅读(493)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示