• 第一次发布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

  • 相关阅读:
    Zookeeper初见
    常见一致性协议(二)
    常见一致性协议(一)
    分布式理论基础
    expose a port on a living Docker container
    tomcat远程调试参数备忘
    bash: ifconfig: command not found
    解决 :java -version出现错误:“could not open `C:Program FilesJavajre7libamd64jvm.cfg”
    centos7 安装 NVIDIA Docker
    解决: httpclient ssl 验证导致死锁问题
  • 原文地址:https://www.cnblogs.com/hdwang/p/16318620.html
Copyright © 2020-2023  润新知