当前位置: 首页 > news >正文

github把自己的jar包发送到maven中央仓库

maven中央仓库注册账号

《Maven中央仓库官网》

注册账号

在这里插入图片描述

直接使用github账号

在这里插入图片描述

他会自动帮我们创建一个github的命名空间

在这里插入图片描述

获取自己的User Token

在这里插入图片描述
在这里插入图片描述
切记立马复制、保存username和password,后面maven的settings.xml会用到,因为这个页面会在一分钟以后自动关闭!!!

打开maven的setting.xml文件

	<servers><server><!-- 这个 id 要和 pom.xml 配置的 central-publishing-maven-plugin 插件的 publishingServerId 一致 --><id>central</id><username>上面的username【短的】</username><password>上面的password【长的】</password></server></servers>

pom.xml

<project><modelVersion>4.0.0</modelVersion><!-- 同Central Portal Namespaces --><groupId>io.github.meta39</groupId><!-- 项目名称 --><artifactId>gzsjkt</artifactId><!-- 版本号 --><version>1.0.0</version><!-- 推荐 --><packaging>jar</packaging><!-- 推荐 --><name>${project.groupId}:${project.artifactId}</name><!-- 描述:最好不要用中文 --><description>A application used as gzsjkt api.</description><!-- 你这个项目的 github 地址 --><url>https://github.com/Meta39/gzsjkt</url><licenses><!-- 协议 --><license><name>The Apache License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url></license></licenses><developers><!-- 开发者信息 --><developer><!-- 开发者姓名 --><name>Meta39</name><!-- 开发者邮箱【推荐使用谷歌邮箱】 --><email>97meta@gmail.com</email><!-- 组织 --><organization>None</organization><!-- 组织地址【可以填自己的github地址】 --><organizationUrl>https://github.com/Meta39</organizationUrl></developer></developers><scm><!-- github 当前项目的连接地址 --><connection>scm:git:git://github.com/Meta39/gzsjkt.git</connection><!-- github 当前项目的 ssh 连接地址 --><developerConnection>scm:git:ssh://github.com/Meta39/gzsjkt.git</developerConnection><!-- github 当前项目的主分支地址 --><url>http://github.com/Meta39/gzsjkt/tree/main</url></scm><properties><!-- 配置参数 --><maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version><maven-source-plugin.version>3.3.1</maven-source-plugin.version><maven-javadoc-plugin.version>3.11.2</maven-javadoc-plugin.version><maven-gpg-plugin.version>3.2.7</maven-gpg-plugin.version><central-publishing-maven-plugin.version>0.7.0</central-publishing-maven-plugin.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>21</java.version><maven.compiler.source>${java.version}</maven.compiler.source><maven.compiler.target>${java.version}</maven.compiler.target></properties><dependencies><!-- 省略依赖 --></dependencies><build><plugins><!-- Maven 插件:编译 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${java.version}</source><target>${java.version}</target></configuration></plugin><!-- Maven 插件:源码 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>${maven-source-plugin.version}</version><executions><execution><id>attach-sources</id><goals><goal>jar</goal></goals></execution></executions></plugin><!-- Maven 插件:javadoc --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>${maven-javadoc-plugin.version}</version><configuration><javadocExecutable>${java.home}/bin/javadoc</javadocExecutable><additionalJOptions><additionalJOption>-Xdoclint:none</additionalJOption></additionalJOptions></configuration><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions></plugin><!-- Maven插件:gpg[本地电脑还需安装gpg] --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>${maven-gpg-plugin.version}</version><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals><configuration><gpgArguments><arg>--pinentry-mode</arg><arg>loopback</arg></gpgArguments></configuration></execution></executions></plugin><!-- Maven 插件:发布 --><plugin><groupId>org.sonatype.central</groupId><artifactId>central-publishing-maven-plugin</artifactId><version>${central-publishing-maven-plugin.version}</version><extensions>true</extensions><configuration><!-- settings.xml 配置的 servers.server.id --><publishingServerId>central</publishingServerId><!-- 自动推送 --><autoPublish>true</autoPublish></configuration></plugin></plugins></build></project>

点击右上角的help跳转到教程界面,安装GPG

在这里插入图片描述

下载GPG

在这里插入图片描述

根据自己的操作系统进行下载

在这里插入图片描述
全部默认安装,路径建议选一个自己记得住的,等会要配置环境变量。

配置GPG环境变量,如下所示:

在这里插入图片描述

在这里插入图片描述

配置完以后输入以下命令:

确保输出版本信息

gpg --version

输出如下信息表示成功

gpg (GnuPG) 2.4.7
libgcrypt 1.11.0
Copyright (C) 2024 g10 Code GmbH
License GNU GPL-3.0-or-later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.Home: C:\Users\X\AppData\Roaming\gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

打开GPG,生成GPG密钥

在这里插入图片描述

填写信息

在这里插入图片描述

然后输入passphrase【需要配置到环境变量】

passphrase就是GPG的密码【自定义的,不是生成的!!!】
环境变量名

MAVEN_GPG_PASSPHRASE

在这里插入图片描述

在服务器上发布

在这里插入图片描述

如果无法验证,可以更换网址【可以就不用管这个,接着往下走】

在这里插入图片描述

修改默认网址:keyserver.ubuntu.com【可以就不用管这个,接着往下走】

一般默认网址都是可以用的,除非用不了才用下面这2个,更换网址后重新生成即可

keys.openpgp.org
pgp.mit.edu

在这里插入图片描述

查看证书

双击生成的证书即可查看证书,或者右键点击“细节”
命令行查看证书

gpg --list-keys

输出内容如下所示

[keyboxd]
---------
pub   ed21312 2025-04-25 [SC] [expires: 2028-04-25]207EC512B1A6F2C63A2EE3807D64B111870BC738
uid           [matetiul] Meta39 <97meta@gmail.com>
sub   cv25519 2025-04-25 [E] [expires: 2028-04-25]

207EC512B1A6F2C63A2EE3807D64B111870BC738要配到setting.xml

在这里插入图片描述

复制你的指纹,如:【207EC512B1A6F2C63A2EE3807D64B111870BC738】

setting.xml增加server

<servers><server><!-- 这个 id 要和 pom.xml 配置的 central-publishing-maven-plugin 插件的 publishingServerId 一致 --><id>central</id><username>上面的username【短的】</username><password>上面的password【长的】</password></server><server><!-- 默认:不要改 --><id>gpg.passphrase</id><passphrase>GPG生成的指纹</passphrase></server></servers>

在你项目的pom.xml同级运行mvn命令推送jar包

mvn clean deploy

出现BUILD SUCCESS就表示推送成功了

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Maven中央仓库查看Namespace =》 Deployments,如下所示是发布成功。

正在发布是会有延迟的。需要等待几分钟才能在maven中央仓库查到自己的jar包
在这里插入图片描述

Maven中央仓库查看查看自己发布的jar包

如:gzsjkt
如下所示:
在这里插入图片描述

github发布Releases自动发布jar包

命令行导出指纹的secret-key

指纹:如:207EC512B1A6F2C63A2EE3807D64B111870BC738

gpg --export-secret-keys --armor 207EC512B1A6F2C63A2EE3807D64B111870BC738

如下所示

-----BEGIN PGP PRIVATE KEY BLOCK-----lIYEaAuWjxYJKwYBBAHaRw8BAQdAEDyPX6jz4itdRBR8UOm6aH2L9b0KQx7EqyoW
Oen/lY7+BwMCWXpixlXJTFTOuw+32S1D/oOoX18MAflzaXq+Vo0zhMjrKoSkfPjP
7iFLWnTVRQtDw5ErJAG7rbDG9n8hSOYFuCbq1PVsADyEDUovs+3CjLQZTWV0YTM5
IDw5N2aldGFAZ21haWwuY29tPoiZBBMWCgBBFiEEKxpvcLxzgmSxEYxjou4yB+xR
gH0FAmgLlo8CGwMFCQWkXjEFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQ
ou4yB+xRgH0g3gD/GqFSFJtCjX2K91c2idS6iSM26EXlkYXn0Ee+iSIur//QA/RZ
AlY0NcHPlfu9MINsHd5Uu9WlOui2ma074dauAn0FnIsEaAuWjxIKKwYBBAGXVQEF
AQEHQJVfEUk/+YmbNooAwEIB/8HAwK9neBQf1S5qRPOmGrqvtqvwZ/FCYB2MlmVr
rVahAc5v7xKL4ySLREZjAznGf8Cu4VgD/evYPXWGJh9VK5hZrhfceXBe/0mFsMoz
4K4LgshbePYwrD+ZvFqln6fkfQvJTFiMKQCTiH4EGBYKACYWIQQrGmkBj5OukofH
jGOi7jIH7FGAfQUCaAuWjwIbDAUJBaReMQAKCRCi7jIH7FGAfVHlAP9wvHOCZLER
JxMlQxWKuUnaYV+8axTsXuN7sXaW56jrwXVgt7XuxkYfWfFXSHpF0qlcL9/eQCp5
Vw8r/PF1ZTdrfQs=
=WY5a
-----END PGP PRIVATE KEY BLOCK-----

待完成…


http://www.mrgr.cn/news/100204.html

相关文章:

  • 代码随想录算法训练营day11(二叉树)
  • spring中的@bean注解详解
  • 点云从入门到精通技术详解100篇-基于二次误差和高斯混合模型的点云配准算法
  • Linux 内核网络协议栈中 inet_stream_ops 与 tcp_prot 的深度解析
  • Windows同步技术-使用命名对象
  • 搜索二叉树-key的搜索模型
  • 霍格软件测试-JMeter高级性能测试一期
  • 【音视频】AVIO输入模式
  • 蓝桥杯 3. 密码脱落
  • iOS/Android 使用 C++ 跨平台模块时的内存与生命周期管理
  • 施磊老师基于muduo网络库的集群聊天服务器(七)
  • OpenHarmony之电源管理子系统公共事件定义
  • FX10(CYUSB4014)USB3.2(10Gbps)开发笔记分享(1):硬件设计与开发环境搭建
  • CMake ctest
  • 用diffusers库从单文件safetensor加载sdxl模型(离线)
  • 深入解析 Linux 中动静态库的加载机制:从原理到实践
  • 深入解析YOLO v1:实时目标检测的开山之作
  • PCI 总线学习笔记(五)
  • 蜜罐管理和数据收集服务器:Modern Honey Network (MHN)
  • 高效使用DeepSeek对“情境+ 对象 +问题“型课题进行开题!