发布jar到maven中央仓库(最新)ps:这是一个微信支付的jar

1 篇文章 0 订阅
1 篇文章 0 订阅

其实网上有很多类似的文章,这里我只是记录下我自己发布成功的一个流程,和踩的坑

准备工作:

  1. 首先,要在https://issues.sonatype.org申请一个账号
  2. 在gitee或者github上创建一个项目,就是你要上传的jar的源码项目,如果已经有可以忽略
  3. 得有一个属于自己的域名,或者说有这个域名的管理权限,这个是用来审核用的,其他方式也可以,这种方式审核最快,我也是用这种方式,具体怎么用在后面会介绍。

准备好以上工作后,现在具体操作:

一.登录

1.登录https://issues.sonatype.org,点击创建按钮来创建一个新的issues工单

在这里插入图片描述

2.随后你会收到一封邮件,或者在你发布的这个工单下会看到他们工作人员的留言

在这里插入图片描述

其实他们主要审核的就是这个GroupId ,这里他说了两点验证方式,用第一种最快,这里介绍第一种,这也就是前面说的为什么要用自己的域名或者有管理权限的了,这里我用阿里云申请的域名,

在这里插入图片描述

然后去你的新建的工单底下用英文回复,说你拥有此域名,并且添加了那条TXT记录,再截个图一并发出去。

二. 配置 GPG:

打开 https://www.gpg4win.org/ 下载 GPG,点下一步直接安装。

记住一点,安装完 一定要重启电脑,别人我不知道,反正在这我坑了好久!

在这里插入图片描述

  • 打开创建一个密钥对,
  • 输入姓名和邮箱,
  • 最后确认新建,
  • 新建完成会创建结果中会有一个指纹,直接复制下来。
  • 过程中需要自己输入一个8位以上的密码,请记住该密码,后面还需要用到.
    在这里插入图片描述

三.上传公钥到 GPS key-servers

打开命令提示符窗口,输入下面命令将证书发送到远程服务器

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 填前面复制的那个指纹

四.配置项目

1.配置 maven 目录 conf 文件夹中的 settings.xml 文件,设置一个 server,里面添加 JIRA 的账号和密码。

注意:这里的id要记住

<servers>
   <server>
      <id>ossrh</id>
      <username>JIRA账号</username>
      <password>JIRA密码</password>
   </server>
</servers>

2.配置 Pom.xml

注意:这里后面有-SNAPSHOT的是快照版,不会发布在中央仓库,要发布中央仓库,去掉-SNAPSHOT即可,参考https://blog.csdn.net/pange1991/article/details/86360229

<?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>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.5.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>注意这里填写你创建工单时候验证的那个groupId</groupId>
	<artifactId>就是用的时候的包名</artifactId>
	<!--注意:这里后面有-SNAPSHOT的是快照版,不会发布在中央仓库,要发布中央仓库,去掉-SNAPSHOT即可-->
	<version>0.0.1-SNAPSHOT</version>
	<url>https://gitee.com/xxx/xxx</url>
	<packaging>jar</packaging>

	<name>safdsafsafa</name>
	<description>sdfsdt</description>

	<!--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>https://gitee.com/xxxx/xxxx.git</url>
		<connection>scm:https://gitee.com/xxxx/xxxx.git</connection>
		<developerConnection>scm:git:https://gitee.com/xxxx/xxxx.git</developerConnection>
	</scm>

	<developers>
		<developer>
			<name>xxxx</name>
			<email>xxxx@xxxx.com</email>
			<organization>https://xxx.com</organization>
			<organizationUrl>https://xxx.com</organizationUrl>
		</developer>
	</developers>
	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		
	</dependencies>
	<build>
		<plugins>
			<!-- doc plugin,Maven API文档生成插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>attach-javadocs</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<!-- resources plugin,Maven 资源插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<id>attach-sources</id>
						<goals>
							<goal>jar-no-fork</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<!-- compiler plugin,Maven 编译插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
					<showWarnings>true</showWarnings>
				</configuration>
			</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://oss.sonatype.org/</nexusUrl>
					<autoReleaseAfterClose>true</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>

	<!-- 这里引入 Settings.xml 中设置的用户名、密码 ,就是前面让你记住的那个ID-->
	<distributionManagement>
		<snapshotRepository>
		<!--就是前面让你记住的那个ID-->
			<id>ossrh</id>
			<url>https://oss.sonatype.org/content/repositories/snapshots</url>
		</snapshotRepository>
		<repository>
			<id>ossrh</id>
			<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
		</repository>
	</distributionManagement>
</project>

最后注意:正常的部署流程应该为:open阶段—>close阶段—>release阶段 执行完成这三个阶段就会发布到中央仓库,
但是我们配置了自动部署,所以不必担心。

<autoReleaseAfterClose>true</autoReleaseAfterClose>

五.发送项目到 Maven 中央仓库

在项目下,执行 maven 命令,部署项目到 Maven 仓库,过程中需要输入之前设置的 GPG 密码,输入一下即可。

mvn clean deploy

由于之前配置了自动发布,所以只要命令执行成功,就等几个小时到https://search.maven.org去搜索自己发布成功的jar吧,

也可以先登录https://oss.sonatype.org,账号密码还是JIRA申请的那个,在这里可以先搜搜看!
在这里插入图片描述

  • 这个网站也就是手动发布的时候,需要登录的,
  • 在Staging Repositories拉到最下,找到自己发布的,
  • 依次open阶段—>close阶段—>release阶段 执行完成这三个阶段就会发布到中央仓库
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT界的奇葩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值