Appearance
maven 上传制品到中央仓库
全程跟着官方教程操作: https://central.sonatype.org/register/central-portal
准备中央仓库账号
中央仓库地址: https://central.sonatype.com
- 先认证命名空间, 命名空间由域名倒序命名
- 准备一个密钥: https://central.sonatype.com/account
- 把密钥信息填入本地的
maven
setting.xml
里面去
xml
<!-- 服务端配置 -->
<servers>
<!--中央仓库-->
<server>
<!--这里注意, central-publishing-maven-plugin 插件的默认 id 是 central-->
<!--可以通过 <publishingServerId>central</publishingServerId> 这个属性更改-->
<!--需要与此处的 id 一致-->
<id>central</id>
<username>xxxx</username>
<password>xxxx</password>
</server>
</servers>
下载 GPG 签名软件
下载地址: https://gnupg.org/download
修改项目 pom.xml 文件
基础内容看这里 (英文, 可以翻译下): https://central.sonatype.org/publish/requirements/#correct-coordinates
要准备4个插件
maven-source-plugin
central-publishing-maven-plugin
maven-gpg-plugin
maven-javadoc-plugin
xml
<build>
<plugins>
<!--源码打包插件, 用于在IDE中查看源码文档-->
<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>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.7</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.11.2</version>
<configuration>
<doclint>none</doclint>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- 打包上传
发布
手动发布
回到网站进行发布.
自动发布
可以通过central-publishing-maven-plugin
插件autoPublish
属性配置自动发布.
xml
<build>
<plugins>
<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>
</plugins>
</build>