这里列出一些发布过程中的注意点:
0. 项目的 pom 需要根据Sonatype OSSRH的要求进行整改
以下信息都必须配置:
- Supply Javadoc and Sources
- Sign Files with GPG/PGP
- Sufficient Metadata
- Correct Coordinates
- Project Name, Description and URL
- License Information
- Developer Information
- SCM Information
配置可以参考:https://www.cnblogs.com/fundebug/p/how-to-deploy-jar-to-maven-central-repository.html
1. javadocs 的验证非常严格,在上传 javadoc 时需要做降级处理,关闭doclint。
maven 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>
see: https://blog.csdn.net/maikelsong/article/details/80828947
2. gpg 验证易出问题,建议手动下载 gpg4win 来进行配置
下载地址: https://gpg4win.org/download.html
3. gpg 签名验证如果报如下错
gpg: cannot open tty `no tty': No such file or directory
或者 找不到 gpg.exe
可以在 maven 中手动配置 gpg 地址:
<properties> <gpg.passphrase>生成密钥时输入的passphrase</gpg.passphrase> <!-- gpg.exe的绝对路径,在gpg安装目录下的bin目录中 --> <gpg.executable>C:Program Files (x86)GnuPGingpg.exe</gpg.executable> <!-- 上一步执行gpg - -list-key命令输出的路径,一般在C:User当前用户AppDataRoaminggnupg --> <gpg.homedir>C:/Users/Administrator/AppData/Roaming/gnupg</gpg.homedir> </properties>
see: https://blog.csdn.net/qq_35433926/article/details/99317773
4. 如果 gps 签名正常,但发布后报找不到签名 key ,可以试着将 key 多发几个服务器:
gpg --keyserver http://pool.sks-keyservers.net:11371 --send-keys 200193FF0AFA3142D18C52411D90CBED00686B93 gpg --keyserver http://keyserver.ubuntu.com:11371 --send-keys 200193FF0AFA3142D18C52411D90CBED00686B93 gpg --keyserver http://keys.gnupg.net:11371 --send-keys 200193FF0AFA3142D18C52411D90CBED00686B93 gpg --keyserver http://keys.openpgp.org:11371 --send-keys 200193FF0AFA3142D18C52411D90CBED00686B93
5. 推荐 Staging Repositories 自动 colse 插件,可以不用去 sonatype 上手动 close
<!--Nexus Staging Maven插件是将组件部署到OSSRH并将其发布到Central Repository的推荐方法--> <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://oss.sonatype.org/</nexusUrl> <autoReleaseAfterClose>true</autoReleaseAfterClose> </configuration> </plugin>
注:maven settings.xml 中要配置 id 为 ossrh 的 server,为此 server 设置 sonatype 的用户名、密码
形如:
<servers> <server> <id>snapshots</id> <username>kvn</username> <password>密码</password> </server> <server> <id>releases</id> <username>kvn</username> <password>密码</password> </server> <server> <id>ossrh</id> <username>kvn</username> <password>密码</password> </server> </servers>
6. 如果 IDEA 当中 deploy 时失败,可以尝试使用 git bash 命令行来执行试试
git clean deploy -Dmaven.test.skip=true -Dgpg.passphrase=gpg密码
---------------------------------------------------------------------------
发布步骤可以参考:
https://blog.csdn.net/alinyua/article/details/83687250
https://blog.csdn.net/weixin_38096157/article/details/88951278
https://blog.csdn.net/qq_35433926/article/details/99317773
gpg配置:
http://c.biancheng.net/view/4832.html
百度搜索关键词可以出来很多教程:
使用gpg签名java工程发布到仓库