注册Sonatype的账户
在Sonatype上提交关于本项目的发布申请
点击页面上方 Create 按钮即可创建此项目的 Issue。
Project: Community Support - Open Source Project Repository Hosting (OSSRH)
Issue TypeRequired: New Project
Summary: java-toolkits (自己项目名称)
Group Id:com.github.songyz0310 (maven项目坐标 Group Id)
Project URL:https://github.com/songyz0310/java-toolkits (项目地址)
SCM url:https://github.com/songyz0310/java-toolkits.git (源代码地址)配置Maven
xml
<server>
<id>sonatype-nexus-snapshots</id>
<username>Sonatype账号</username>
<password>Sonatype密码</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>Sonatype账号</username>
<password>Sonatype密码</password>
</server>配置项目 pom.xml 文件
增加开源许可协议,SCM信息,开发者信息等待根据自己信息填写即可
xml
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git:https://xxxx/xxx.git</connection>
<developerConnection>scm:git:xxxx.git</developerConnection>
<url>git:https:/xxxxxx.git</url>
</scm>
<developers>
<developer>
<name>xxx</name>
<email>xxxx</email>
<organization>xxx</organization>
</developer>
</developers>如果发布Release版本,需要添加Release的相关profile配置,distributionManagement节和maven-compiler-plugin节的配置信息根据自己的实际情况做修改。
xml
<profile>
<id>release</id>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<additionalparam>-Xdoclint:none</additionalparam>
<!-- TODO 临时解决不规范的javadoc生成报错,后面要规范化后把这行去掉 -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!--Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<verbose>true</verbose>
<encoding>UTF-8</encoding>
<showWarnings>false</showWarnings>
</configuration>
</plugin>
<!--Release -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>配置PGP的公钥信息
Windows
Windows下使用gpg4win来进行配置。 下载地址 安装好之后,打开cmd控制台,使用 gpg --list-keys 命令来查询自己配置的key 如果提示gpg不是可执行程序或命令,请配置Path路径到 GnuPG 的bin目录
生成密钥的命令 gpg --gen-key,过程中需要使用到姓名、邮箱等信息,这里的配置最好和Sonatype注册信息、pom文件配置信息保持一致,以免不必要的麻烦。 生成的过程中,会有个弹框要求输入Passphase信息,这个是密钥的密码,同样需要记牢。发布签名的过程中会用得到。
使用 gpg --list-keys 命令查询配置好的公私钥信息,使用 gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys <公钥key> 将公钥信息发送到ubuntu.com服务器,后续推送maven仓库会做校验。
Linux ubuntu
shell
sudo apt install gpg
sudo apt update && sudo apt install gnupg -y
# 生成证书
gpg --full-generate-key
# 语法:gpg --send-keys --keyserver [服务器地址] [密钥ID]
# 发布公钥
gpg --send-keys --keyserver keyserver.ubuntu.com 1234567890ABCDEF
## 导入私钥
gpg --import /server/qolome_0x9910B8DA_SECRET.asc
## 导入公钥
gpg --import /server/qolome_0x9910B8DA_public.asc
## 导入公钥
# 哪个用户需要就使用哪个用户执行以下命令
gpg --list-secret-keys
# 方式1:通过密钥ID下载(最常用)
gpg --recv-keys --keyserver keyserver.ubuntu.com 1234567890ABCDEF
# 验证下载结果
gpg --list-keys 1234567890ABCDEF
# 进入密钥编辑模式
# 替换为你的密钥ID/邮箱/指纹
gpg --edit-key 1234567890ABCDEF
# 1. 执行trust命令,进入信任设置
trust
# 2. 选择信任级别(根据实际场景选,推荐选5):
# 1 = 我不知道或不关心
# 2 = 我不信任
# 3 = 我勉强信任
# 4 = 我信任
# 5 = 我完全信任
5
# 3. 确认选择(输入y)
y
# 4. 保存并退出
save