上传jar包到中央仓库(2023.06.13)一文搞定

本文发布时间 (2023.06.13)

步骤

〇、文章说明

本文章使用的网址、工具、环境等版本如下,注意这些的版本不是太重要:

  1. 发布jar包的后台审核:https://issues.sonatype.org/secure/Dashboard.jspa
  2. gpg4win-4.1.0
  3. git2.41.0
  4. maven3.9.2
  5. idea2023
  6. jdk17
  7. springboot3.0

没有就自取吧

链接:https://pan.baidu.com/s/12TZjJaPXHKk3IJdNereymQ?pwd=u0ig
提取码:u0ig
–来自百度网盘超级会员V4的分享

一、注册 sonatype 并创建 issue 并通过检查

看这篇文章 链接

二、安装GPG并创建密钥

看这篇文章 链接

三、mvn, git, pom 配置

参考文档:https://central.sonatype.org/publish/publish-maven/

mvn

  1. 不管你之前的settings.xml在哪里,修改完成后请复制一份到 C:\Users\YCL\.m2 文件夹中。因为部署时读取的是这里面的数据而非你配置的工程的settings
  2. settings.xml 的 (servers.server.idprofiles.profile.idactiveProfiles.activeProfile)与 pom.xml 的 (build与profiles 的插件 nexus-staging-maven-plugin.configuration.serverId)必定相同
    <servers>
        <server>
            <id>ossrh</id>
            <username>sonatype账号</username>
            <password>sonatype密码</password>
        </server>
    </servers>

    <profiles>
        <profile>
            <id>jdk-17</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>17</jdk>
            </activation>
            <properties>
                <maven.compiler.source>17</maven.compiler.source>
                <maven.compiler.target>17</maven.compiler.target>
                <maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
            </properties>
        </profile>

        <profile>
            <id>ossrh</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <gpg.executable>GnuPG的路径, 注意不是Gpg4win, 示例: {E:\gpg\GnuPG}\bin\gpg.exe</gpg.executable>
                <gpg.passphrase>生成密钥时自己输入的密码</gpg.passphrase>
                <gpg.homedir>人家默认存放的路径, 改一下我的, 示例: {C:\Users\YCL}\AppData\Roaming\gnupg\</gpg.homedir>
            </properties>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>ossrh</activeProfile>
    </activeProfiles>

git

  1. 文件位置: C:\Users\YCL\.gitconfig
  2. 关注两个:一个是签名密钥,就是gpg生成的,长的也行短的也行;一个是 GnuPG位置
[user]
	signingkey = 生成密钥时自己输入的密码
[gpg]
	program = GnuPG的路径, 注意不是Gpg4win, 示例: {E:\gpg\GnuPG}\bin\gpg.exe

pom

  1. 以下全是必配的,在deploy时有检查,检查不通过是无法发布的,建议直接复制改一下
  2. build 和 profiles.profile.build 是一样的,只是后者后面还加了一个插件
    <description>提示</description>
    <url>git工程地址</url>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>自己的id</id>
            <name>自己的name</name>
            <email>自己的邮箱</email>
            <timezone>+8</timezone>
            <roles>
                <role>manager</role>
            </roles>
        </developer>
    </developers>

    <scm>
        <connection>git工程地址</connection>
        <developerConnection>git工程地址</developerConnection>
        <url>git工程地址</url>
    </scm>

    <distributionManagement>
        <repository>
            <id>release</id>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
        <snapshotRepository>
            <id>snapshot</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <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>
    <profiles>
        <profile>
            <id>release</id>
            <build>
                <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>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <additionalparam>-Xdoclint:none</additionalparam>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <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>
                    <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 nexus-staging:release</goals>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

四、发布工程

  1. 发布时会遇到各种各样的问题,这里无法穷举,自行百度吧
  2. 注意别在什么地方写跳过什么东西的打包,如在pom.properties里写<maven.javadoc.skip>true</maven.javadoc.skip>(两个星期的血的教训。。。。。。。。 ˚‧º·(˚ ˃̣̣̥᷄⌓˂̣̣̥᷅ )‧º·˚ )

我直接在idea里点deploy。如果在gpg生成密钥时有密码的话,这时会提示输入密码,就是gpg的密码。
出现build success就可以了,网上很多都是说在nexus里去close再发布release,我觉得没必要,因为idea已经帮我们集成了,能一步到位的事情我也懒得去拆分成几步做哈哈哈哈

在这里插入图片描述

然后在 nexus 仓库 https://s01.oss.sonatype.org/ 里能看到

在这里插入图片描述

这里也能看,不过好像只能看到最终版的 https://repo1.maven.org/maven2

在这里插入图片描述

好像阿里镜像是一天同步一次,也就是说今天发布的应该明天就能看到了,或者后天,我去年年末写的一个工程就构建上去了,不过只有class,没有源文件,所以这次重新做一下并记录下来。

在这里插入图片描述

PS

2023.06.16新增:

今天上来阿里镜像仓库 https://mvnrepository.com/ 看,真的有了
在这里插入图片描述

到这里就完啦!!

为弄好他我花了半年,一步一步被卡过来的。。。。
每一步网上都是不同的说法,但都没效果,最过分的是不知哪位损友让在properties里面加上<maven.javadoc.skip>true</maven.javadoc.skip>,导致javadoc一直生成不出来,发布时一直报关闭异常没有找到javadoc的jar包,足足卡了两个星期。。。。。。。。。

请添加图片描述

End

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值