本文发布时间 (2023.06.13)
目录
步骤
〇、文章说明
本文章使用的网址、工具、环境等版本如下,注意这些的版本不是太重要:
- 发布jar包的后台审核:https://issues.sonatype.org/secure/Dashboard.jspa
- gpg4win-4.1.0
- git2.41.0
- maven3.9.2
- idea2023
- jdk17
- 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
- 不管你之前的
settings.xml
在哪里,修改完成后请复制一份到C:\Users\YCL\.m2
文件夹中。因为部署时读取的是这里面的数据而非你配置的工程的settingssettings.xml
的 (servers.server.id
与profiles.profile.id
与activeProfiles.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
- 文件位置:
C:\Users\YCL\.gitconfig
- 关注两个:一个是
签名密钥
,就是gpg生成的,长的也行短的也行;一个是GnuPG位置
[user]
signingkey = 生成密钥时自己输入的密码
[gpg]
program = GnuPG的路径, 注意不是Gpg4win, 示例: {E:\gpg\GnuPG}\bin\gpg.exe
pom
- 以下全是必配的,在deploy时有检查,检查不通过是无法发布的,建议直接复制改一下
- 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>
四、发布工程
- 发布时会遇到各种各样的问题,这里无法穷举,自行百度吧
- 注意别在什么地方写跳过什么东西的打包,如在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包,足足卡了两个星期。。。。。。。。。