1,通过第三方仓库(sonatype ossrh)上传,首先在官网注册账号:
2,新建issue
3,按照评论要求进行代码建立等
4,安装gpg,地址:Gpg4win - Download Gpg4win
相关命令:
gpg --version 查看版本(是否安装成功)
gpg --gen-key 生成公钥
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公钥ID或上面提到的key 将公钥发送gpg服务器
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 公钥ID或上面提到的key 检查是否发送成功
gpg --list-keys 查看生成的公钥
5,在maven的setting.xml配置添加:
<servers>
<!-- 上传jar包到maven中央仓库配置start -->
<server>
<id>ossrh</id>
<username>Sonatype账号</username>
<password>Sonatype密码</password>
</server>
<!-- 上传jar包到maven中央仓库配置end -->
</servers>
6,部署发布
mvn clean deploy
7,同步到maven中央仓库
到 https://oss.sonatype.org/#stagingRepositories 中勾选自己上传的构件(我们的jar包上传到这里哦)点击Close然后再Release,Release之后就会同步到maven中央仓库
注:在发送公钥到gpg服务器时,如果出现 gpg: keyserver send failed: No name,先试着换换服务器,如果还是不行可能是因为本地开了代理,关掉代理就可以了。(之前用星巴克电脑就出现过这种问题,找了半天没找到原因,后来关掉就好了)
参照:
Maven(6) Java上传本地jar包到maven中央仓库_java -jar maven-upload.jar-CSDN博客
更新JAR到maven仓库 gpg: keyserver send failed: No name-CSDN博客
注:
1,settings.xml中要配置 ossrh的账号、密码
2,groupID需要与提交的issure中的groupID保持一致
3,在打包doc时,项目代码不能出现中文类注释,否则会报错
4,当存在多个gpg 的公钥时,需要指定公钥的name和密码,否则默认会取第一个
5,发布完成后可在sonatype中查看,然后评论,听过审核后他们才会同步到maven中央仓库中。
6,在https://s01.oss.sonatype.org/已存在后,需要先close下,如果成功则等待结果;否则drop掉重新部署。
参照:Releasing the Deployment - The Central Repository Documentation
7,部署时,-SNAPSHOT的不能同步到中央仓库,只有release版本才会同步。
8,如果在sonatype上close后出现:Signature Validation错误,可能是gpg接收服务器出现问题,可以通过 gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 6E4F9C26B7463E945375256E9F3772DE6A9C5FD2 看下是否接收成功,如果失败,可以参照:gpg signature - `gpg: keyserver send failed: No keyserver available` when sending to hkp://pool.sks-keyservers.net - Stack Overflow
9,如果sonatype上存在高版本的项目了,本地在deploy时不能低于上传的版本,否则会报错。
关于以上问题可以参照:Java上传本地jar包到maven中央仓库的坑逼经历_gpg.exe' 不是内部或外部命令,也不是可运行的程序-CSDN博客
--------------------------------------------------------------------------------------------settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- <localRepository>C:\Users\ymyu\.m2\repository</localRepository> -->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>ossrh</id>
<username>lizhihao</username>
<password>Liabc812w925%</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>nexus-aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<!-- <url>https://maven.aliyun.com/repository/central</url> -->
</mirror>
</mirrors>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>b812w925</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
---------------------------------------------------------- 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">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.thinkersone.yapi.generator</groupId>
<artifactId>yapi-generator</artifactId>
<version>2.4-SNAPSHOT</version>
<packaging>pom</packaging>
<name>io.github.thinkersone.yapi.generator</name>
<url>http://www.yapi.generator.com</url>
<modules>
<module>yapi-common</module>
<module>yapi-core</module>
<module>yapi-example</module>
<module>yapi-rule</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.68</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>
<!-- freemark模板引擎 -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.12.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13-beta-3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.25</version>
</dependency>
</dependencies>
</dependencyManagement>
<!--licenses信息-->
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<!--scm信息-->
<scm>
<url>http://chendahai.cn</url>
<connection>scm:git:https://github.com/chywx/demo-spring-boot-starter.git</connection>
<developerConnection>scm:git:https://github.com/chywx/demo-spring-boot-starter.git</developerConnection>
</scm>
<!--发布者信息-->
<developers>
<developer>
<name>lizhihao</name>
<email>2415612109@qq.com</email>
<organization>https://github.com/thinkersOne</organization>
<organizationUrl>https://github.com/thinkersOne</organizationUrl>
</developer>
</developers>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<!--source-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!--javadoc-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<charset>UTF-8</charset>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- gpg plugin,用于签名认证 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!--staging puglin,用于自动执行发布阶段(免手动)-->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- release plugin,用于发布到release仓库部署插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
</plugin>
</plugins>
</build>
<!--定义snapshots库和releases库的nexus地址-->
<distributionManagement>
<snapshotRepository>
<!--oss需要对应到settings.xml下的service的id-->
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</project>