注册 Sonatype

下载gpg并生成密钥
sh
# 检查版本
gpg -version
# 生成密钥,会提醒你输入name和email,按提示输入两个属性值后,输入O结束。
gpg --gen-key
# 查看密钥
gpg --list-keys
# 发布公钥
gpg --keyserver keyserver.ubuntu.com --send-keys 刚刚生成的公钥
# 验证公钥(一般隔天才能验证出来)
gpg --keyserver keyserver.ubuntu.com --recv-keys 502D2321AB02BE29

导出私钥
sh
gpg --armor --export-secret-keys 502D2321AB02BE29
修改 xml
创建用户令牌

直接写到 maven 的xml文件里
xml
<settings>
<servers>
<server>
<id>central</id>
<username>GVnq6g</username>
<password>oIQntX8k8xumEjOMIfSVF00BhGACHDR0Q</password>
</server>
</servers>
</settings>
在 pom 文件
xml
<distributionManagement>
<repository>
<id>central</id>
<url>https://central.sonatype.com/api/v1/publisher</url>
</repository>
</distributionManagement>
完整pom模板
xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>io.github.k3109405015</groupId>
<artifactId>yu-tool</artifactId>
<version>1.0.0</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<name>nzfisl1v2o</name>
<description>综合工具框架</description>
<url>https://github.com/k3109405015/nzfisl1v2o.git</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>GaoYu</name>
<email>3109405015@qq.com</email>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/k3109405015/nzfisl1v2o.git</connection>
<developerConnection>scm:git:ssh://github.com/k3109405015/nzfisl1v2o.git</developerConnection>
<url>https://github.com/k3109405015/nzfisl1v2o</url>
</scm>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<distributionManagement>
<repository>
<id>central</id>
<url>https://central.sonatype.com/api/v1/publisher</url>
</repository>
</distributionManagement>
<dependencies>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>6.2.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>6.2.11</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
<version>2.21.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.7.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.7</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-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>