进入到Maven Central: Publishing (sonatype.com)网页并且使用github账号登录:
github新建repository :你的github用户名.github.io
中央仓库新建nameSpace :io.github.github用户名
安装gpg,获取指纹密钥:
安装时记住安装目录地址:
查看指纹密钥,设置gpg密码(后面要用):
添加配置到上传项目pom文件:
<groupId>io.github.z19235</groupId>
<artifactId>myapi-common</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>myapi-common</name>
<url>https://github.com/Z19235/myapi-common</url>
<scm>
<url>https://github.com/Z19235/myapi-common</url>
<connection>scm:git:https://github.com/Z19235/myapi-common.git</connection>
<developerConnection>scm:git:https://github.com/Z19235/myapi-common.git</developerConnection>
</scm>
<developers>
<developer>
<!--此处填写gpg用户id-->
<id>dell</id>
<!--此处填写gpg用户名-->
<name>dell</name>
<!--此处填写gpg邮箱-->
<email>1923532529@qq.com</email>
<url>https://github.com/github用户名/myapi-common</url>
<timezone>+8</timezone>
</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>
<build>
<plugins>
<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>
<!-- 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>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<!-- Gpg Signature -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<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.5.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>central</id>
<url>https://central.sonatype.com/</url>
</snapshotRepository>
</distributionManagement>
进入IDEA,打开Setting中的Maven设置项,找到本机Maven配置文件setting.xml地址:
添加Maven配置至setting.xml:
<profiles>
<profile>
<id>central</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!--此处填写gpg安装地址-->
<gpg.executable>F:\computer\GnuPG\bin\gpg</gpg.executable>
<!--此处填写gpg密码-->
<gpg.passphrase>***</gpg.passphrase>
</properties>
</profile>
</profiles>
获取token:
复制并添加入setting.xml:
最终格式:
<servers>
<server>
<id>central</id>
<username>gXeZ3lod</username>
<password>X/vW/kHEzJMOAmt2Azrt7YehcOcEIE1u8TEZBRuzoap2</password>
</server>
</servers>
<profiles>
<profile>
<!-- id固定写为central -->
<id>central</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>F:\computer\GnuPG\bin\gpg</gpg.executable>
<gpg.passphrase>之前设置的gpg密码</gpg.passphrase>
</properties>
</profile>
</profiles>
注意:Maven配置文件setting.xml修改完记得点保存
选择上传项目点击deploy(注意:每次上传前都要重新复制userName和passWord否则报错401):
运行结果如下:
点击Publish发布:
查看依赖上传情况:
查询依赖:
调用依赖成功:
参考博客出处: