在Sonatype上申请,将自己的项目发布到maven中央仓库
在Sonatype上申请,将自己的maven项目发布到maven中央仓库准备工作Sonatype账号注册注册地址:https://issues.sonatype.org/secure/Signup!default.jspa验证过程注意事项sonatype官方详细教程事项如下如官方文章所述:选择座标,您必须为您拥有的域或您代表所有者指定维护者的域选择一个groupId。使用github作为自己的gr
准备工作
Sonatype账号注册
注册地址:https://issues.sonatype.org/secure/Signup!default.jspa
验证过程注意事项
事项如下
如官方文章所述:
- 选择座标,您必须为您拥有的域或您代表所有者指定维护者的域选择一个groupId。
- 使用github作为自己的groupId(io.github.username),只要您的项目URL 与请求的groupId匹配,就会立即进行验证。
- 使用自己域名作为groupId,可以通过下列方法之一验证域名所有权:
1、TXT记录验证:
这是最快的验证途径。只需在DNS中创建一个引用OSSRH凭单号的TXT记录,即可批准您的groupId。
2、GitHub重定向:
设置从您的域到托管项目的GitHub URL的重定向。
工单创建
注册完Sonatype账号后,登陆创建issues工单
-
新建一个issue,项目需要选择 Community Support - Open Source Project Repository Hosting
我这里使用的是在阿里云买域名,groupId也是使用自己域名定义的。所以这里project URL配置需要注意一下 -
project URL 配置,使用个人域名TXT记录验证方式配置域名解析
-
提交后时刻关注邮件,安装邮件提示修改即可,一般情况下当天就会有官方回复,直到收到如下结果即可
解决结果: 已修复
top.legendscloud has been prepared, now user(s) herionZhang can:
Publish snapshot and release artifacts to https://s01.oss.sonatype.org
Have a look at this section of our official guide for deployment instructions:
https://central.sonatype.org/publish/publish-guide/#deployment
Please comment on this ticket when you've released your first component(s), so we can activate the sync to Maven Central.
Depending on your build configuration, this might happen automatically. If not, you can follow the steps in this section of our guide:
https://central.sonatype.org/publish/release/
配置发布
GPG签名
- 生成秘钥对
C:\Users\herion>gpg --gen-key
gpg (GnuPG) 2.2.27; Copyright (C) 2021 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Note: Use "gpg --full-generate-key" for a full featured key generation dialog.
GnuPG needs to construct a user ID to identify your key.
Real name: herionZhang
Email address: herionZhang@126.com
You selected this USER-ID:
"herionZhang <herionZhang@126.com>"
Change (N)ame, (E)mail, or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key 2321EC557723B7A1 marked as ultimately trusted
gpg: revocation certificate stored as 'C:/Users/herion/AppData/Roaming/gnupg/openpgp-revocs.d\CB117A******557723B7A1.rev'
public and secret key created and signed.
pub rsa3072 2021-05-26 [SC] [expires: 2023-05-26]
CB117A93262980179EB775812321EC557723B7A1
uid herionZhang <herionZhang@126.com>
sub rsa3072 2021-05-26 [E] [expires: 2023-05-26]
- 将 pub 上传到 key 验证库
C:\Users\herion>gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys CB117A932******EC557723B7A1
gpg: sending key 2321EC557723B7A1 to hkp://keyserver.ubuntu.com:11371
C:\Users\herion>
maven 配置
- 在 settings.xml中配置账号信息
<settings>
<servers>
<server>
<id>ossrh</id>
<username>your-jira-id</username>
<password>your-jira-pwd</password>
</server>
</servers>
</settings>
- maven-gpg-plugin 配置
<profiles>
<profile>
<!-- id 与 pom.xml 的 maven-gpg-plugin 插件中的 id 对应-->
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>你的gpg密码</gpg.passphrase>
</properties>
</profile>
</profiles>
项目pom配置
- 在pom.xml中配置项目信息
<name>spring-cloud-legends</name>
<description>spring-cloud-legends</description>
<url>https://github.com/phoenix-force666/spring-cloud-legends</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/phoenix-force666/spring-cloud-legends.git</connection>
<developerConnection>scm:git:ssh://github.com/phoenix-force666/spring-cloud-legends.git</developerConnection>
<url>https://github.com/phoenix-force666/spring-cloud-legends/tree/master</url>
</scm>
<developers>
<developer>
<name>herionZhang</name>
<email>herionZhang@126.com</email>
</developer>
</developers>
<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>
- 配置构建信息
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</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>
<configuration>
<aggregate>true</aggregate>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<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>1.5</version>
<executions>
<execution>
<id>ossrh</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<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>false</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
发布
- mvn clean deploy
- 输入gpg 签名验证密码
- 等待deploy SUCCESS
herion@DESKTOP-6U2TG0S MINGW64 /f/java_workspace/open_source/spring-cloud-legends (feature/2020.2)
$ mvn clean deploy
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] spring-cloud-legends-dependencies [pom]
[INFO] spring-cloud-legends [pom]
[INFO] spring-cloud-legends-common [jar]
[INFO] spring-cloud-legends-utils [pom]
[INFO] spring-cloud-legends-file [jar]
[INFO] spring-cloud-legends-mock [jar]
[INFO] spring-cloud-legends-starters [pom]
[INFO] spring-cloud-legends-web-starter [jar]
[INFO] spring-cloud-legends-code-generator-starter [jar]
[INFO] spring-cloud-legends-db-starter [jar]
[INFO] spring-cloud-legends-cache-starter [jar]
[INFO] spring-cloud-legends-mail-starter [jar]
[INFO] spring-cloud-legends-file-starter [jar]
[INFO] spring-cloud-legends-project-generator-starter [jar]
[INFO] spring-cloud-legends-monitor-starter [jar]
[INFO] spring-cloud-legends-process-engine-starter [jar]
[INFO] spring-cloud-legends-elastseach-starter [jar]
[INFO] spring-cloud-legends-eureka-starter [jar]
[INFO] spring-cloud-legends-nacos-starter [jar]
[INFO] spring-cloud-legends-apollo-starter [jar]
[INFO]
[INFO] ---------< top.legendscloud:spring-cloud-legends-dependencies >---------
[INFO] Building spring-cloud-legends-dependencies 2020.0.0-M1 [1/20]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ spring-cloud-legends-dependencies ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ spring-cloud-legends-dependencies ---
[INFO] Installing F:\java_workspace\open_source\spring-cloud-legends\spring-cloud-legends-dependencies\pom.xml to d:\develop\maven_jar\top\legendscloud\spring-cloud-legends-dependencies\2020.0.0-M1\spring-cloud-legends-dependencies-2020.0.0-M1.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ spring-cloud-legends-dependencies ---
Uploading to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends-dependencies/2020.0.0-M1/spring-cloud-legends-dependencies-2020.0.0-M1.pom
Uploaded to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends-dependencies/2020.0.0-M1/spring-cloud-legends-dependencies-2020.0.0-M1.pom (6.9 kB at 2.7 kB/s)
Downloading from ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends-dependencies/maven-metadata.xml
Downloaded from ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends-dependencies/maven-metadata.xml (341 B at 635 B/s)
Uploading to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends-dependencies/maven-metadata.xml
Uploaded to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends-dependencies/maven-metadata.xml (341 B at 171 B/s)
[INFO]
[INFO] ---------------< top.legendscloud:spring-cloud-legends >----------------
[INFO] Building spring-cloud-legends 2020.0.0-M1 [2/20]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ spring-cloud-legends ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ spring-cloud-legends ---
[INFO] Installing F:\java_workspace\open_source\spring-cloud-legends\pom.xml to d:\develop\maven_jar\top\legendscloud\spring-cloud-legends\2020.0.0-M1\spring-cloud-legends-2020.0.0-M1.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ spring-cloud-legends ---
Uploading to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends/2020.0.0-M1/spring-cloud-legends-2020.0.0-M1.pom
Uploaded to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends/2020.0.0-M1/spring-cloud-legends-2020.0.0-M1.pom (11 kB at 6.1 kB/s)
Downloading from ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends/maven-metadata.xml
Uploading to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends/maven-metadata.xml
Uploaded to ossrh: https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/top/legendscloud/spring-cloud-legends/maven-metadata.xml (328 B at 161 B/s)
- 登陆 https://s01.oss.sonatype.org/#stagingRepositories 查看jar, close并release
异常
close 出现异常
异常原因
pom没有配置 name、description、url 、license
解决方案
pom中添加如下配置:
<name>spring-cloud-legends</name>
<description>spring-cloud-legends</description>
<url>https://github.com/phoenix-force666/spring-cloud-legends</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
没有sources jar
解决方案
pom-> build->plugins 中添加下maven-source-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>
没有签名文件
解决方案
pom-> build->plugins 中添加下maven-gpg-plugin 插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>ossrh</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
远程sign验证异常
- 异常原因
公钥只发布到了 hkp://pgp.mit.edu 同步需要一定时间
gpg --keyserver hkp://pgp.mit.edu --send-keys 3AF2D04D7*******B4F49D196F
- 解决方法
多根据错误信息多发布到几台服务器
gpg --keyserver hkp://pool.sks-keyservers.net:11371 --send-keys 3AF2D0********4F49D196F
gpg --keyserver hkp://pool.sks-keyservers.net:11371 --recv-keys 3AF2D0********4F49D196F
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 3AF2D0********4F49D196F
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 3AF2D0********4F49D196F
gpg --keyserver hkp://keys.gnupg.net:11371 --send-keys 3AF2D0********4F49D196F
gpg --keyserver hkp://keys.gnupg.net:11371 --recv-keys 3AF2D0********4F49D196F
项目代码
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)