一、注册maven central
账号
https://central.sonatype.com/publishing/namespaces
我这里直接使用github账号登录 ,可以自己注册或者直接使用google账号或者github账号登录
这里github账号登录之后 应该只出现io.github 下面的io.gitee我也验证过 所以这里出现了github和gitee 我这里直接以gitee为例
二、新增Namespace 并且通过验证
这里是一些开源仓库的命名方式
点击Add Namespace
这里我已经操作过了 我新增一个假的
出现了一个gitee的地址 以我之前的为例 https://gitee.com/dengbaikun/6cdhjdt1yz
打开我的gitee 新建仓库
必须是开源的
创建完之后
自己请求一下
https://gitee.com/dengbaikun/6cdhjdt1yz 能否访问 如果可以访问既可以通过验证了
三、配置GPG
到https://gpg4win.org/download.html 下载
进行安装
验证gpg是否验证成功
配置密钥
gpg --gen-key 生成key
gpg --list-keys 查看keys
# 发布公钥
gpg --keyserver keyserver.ubuntu.com --send-keys 5CC07AA0B6236AAC20C25D3421EA2B94594210D3
gpg --keyserver pgp.mit.edu --send-keys 5CC07AA0B6236AAC20C25D3421EA2B94594210D3
#发布密钥到 keys.openpgp.org
gpg --export 邮箱@foxmail.com > my_key.pub
#生成后my_key.pub 通过 https://keys.openpgp.org/upload 上传上去
#验证是否发布成功
gpg --keyserver keyserver.ubuntu.com --recv-keys 5CC07AA0B6236AAC20C25D3421EA2B94594210D3
gpg --keyserver keys.openpgp.org --recv-keys 5CC07AA0B6236AAC20C25D3421EA2B94594210D3
gpg --keyserver pgp.mit.edu --recv-keys 5CC07AA0B6236AAC20C25D3421EA2B94594210D3
四、配置 maven的settings.xml
https://central.sonatype.com/account
<server>
<id>central</id>
<username>asa2gZyr</username>
<password>asdfvo4qXpAOFXNqiA6UQaa1Y6xJKRTuxZ7/MfYVeo1G</password>
</server>
把这段复制到 自己的maven的settings.xml文件中
五、配置 maven项目的pom
下面是必须的完成要加的内容
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<name>dengbaikun</name>
<description>dengbaikun</description>
<url>https://gitee.com/dengbaikun</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<developers>
<developer>
<name>dengbaikun</name>
<email>自己的邮箱</email>
</developer>
</developers>
<scm>
<url>scm:git:git@gitee.com:dengbaikun/6cdhjdt1yz.git</url>
<connection>scm:git:git@gitee.com:dengbaikun/6cdhjdt1yz.git</connection>
<developerConnection>scm:git:git@gitee.com:dengbaikun/6cdhjdt1yz.git</developerConnection>
<tag>master</tag>
</scm>
<distributionManagement>
<snapshotRepository>
<id>central</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>central</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skip>true</skip><!---跳过样式检查-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.15.0</version>
<configuration>
<skip>true</skip>><!---跳过命令检查-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<configuration>
<encoding>UTF-8</encoding>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<additionalOptions>-Xdoclint:none</additionalOptions><!---
这里是为了跳过doc一些验证error变成warn警告 允许通过
-->
</configuration>
<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.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireReleaseDeps>
<message>No Snapshots Allowed!</message>
<onlyWhenRelease>true</onlyWhenRelease>
</requireReleaseDeps>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<gpgArguments>
<arg>--batch</arg>
</gpgArguments>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<tokenAuth>true</tokenAuth>
<autoPublish>true</autoPublish>
<waitUntil>validated</waitUntil>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
最后执行 mvn clean deploy -P release
然后我们根据上图的提示
打开https://central.sonatype.com/publishing/deployments
查看发布情况
等待变绿就可以
检验是否成功可以在这里搜索自己的artifactId
或者可以在 https://repo.maven.apache.org/maven2
这里打开看下有没有自己的包
出现了就代表成功了
六、拉取自己上传的中央仓库包(这里以为maven项目)
在pom中添加
<dependencies>
<dependency>
<groupId>io.gitee.dengbaikun</groupId>
<artifactId>test-deploy</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
就会从repo.maven.apache.org/maven2 拉取刚发布的包