打开 https://issues.sonatype.org/ 注册一个账号。
填入你自己的账号注册信息即可。
登录成功后在导航找到新建点击弹窗新建面板
问题类型:一定要选 New Project
Group ID 需要用自己域名的认证一下归属,也就是ddns解析认证。类似国内申请免费SSL证书流程。,使用github的可以直接用。具体参考https://central.sonatype.org/publish/requirements/coordinates/
其他信息根据项目来
issue创建完成后会等待管理人员审核。这个时间不会很久。这个时候我们可以先配置下本地环境。
gpg签名参考申请gpg签名-Maven上传jar到公共仓库-xqlee (blog.xqlee.com)
打开setting.xml配置文件,在servers节点添加以下信息
<!-- Maven公共仓库 -->
<server>
<id>maven-public</id><!-- 注意这个id名称,后面会用到 -->
<username>中央仓库账号</username>
<password>你的中央仓库账号密码</password>
</server>
...其他内容...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger.ui.version>2.0.8</swagger.ui.version>
<java.version>1.8</java.version>
<springfox.version>2.10.5</springfox.version>
<spring-plugin.version>2.0.0.RELEASE</spring-plugin.version>
<skipTests>true</skipTests>
<maven.javadoc.plugin.version>2.10.4</maven.javadoc.plugin.version>
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<maven-compiler-plugin.version>3.6.2</maven-compiler-plugin.version>
</properties>
...其他内容...
<url>项目地址可以写gihub地址或者你的私人博客</url>
<description>项目描述</description>
<developers>
<developer>
<name>开发者名称(开发者可以有多个)</name>
<email>开发者邮件</email>
</developer>
</developers>
<!--协议许可-->
<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>仓库地址</connection>
<developerConnection>地址</developerConnection>
<url>地址</url>
</scm>
...其他内容...
<profiles>
<!--maven center repository-->
<profile>
<id>maven-public</id><!--注意这里和上面步骤配置setting.xml里面的id保持一致-->
<build>
<plugins>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- sonatype release plugin autoRelease -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>maven-center</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<!--oss-->
<snapshotRepository>
<id>maven-center</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>maven-center</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
配置完成后,刷新下maven项目,然后勾选上刚才的配置
勾选配置后,点击deploy开始部署,部署过程会提示输入gpg签名的密钥,输入步骤3时候填入的签名即可。这个签名密码建议保存好,后面发布都需要。
至此maven发布jar到中央仓库完成。
2023 更新:
自2021年后,中央仓库开放地址做了调整修改为
https://s01.oss.sonatype.org/
一共有三处需要修改,注意!注意!!!!
http://blog.xqlee.com/article/1107.html