自定义项目Jar上传到maven中央仓库(一步到位)

news2024/10/7 16:16:40

中央仓库 Open Source Software Repository Hosting 简称 OSSRH

实现目标:将自定义项目上传至maven中央仓库,其他人只需引入maven坐标即可直接使用

上传步骤:亲测有效

  • 注册账号(去它平台)
  • 提交工单(叫它做事)
  • 人工审核及确认(它说好的)
  • 上传SNAPSHOT版本(我给测试版)
  • 上传release版本(我给稳定版)
  • 完美maven坐标引用(我直接用)

一、注册jira账号

Jira Software

步骤不多说,密码记住,之后要频繁用到

image-20230506114045630

二、创建Issue问题工单

  • 类型:默认
  • Group Id:填域名,github提供免费个人域名io.github.xxx
  • Project URL:项目地址
  • SCM url:项目git地址
  • username:登录用户名
  • Already Synced:初次创建填 No

image-20230506140545387工单创建完成,等待邮件回复。

三、确认回复邮件

邮件回复内容一般为:

​ 内容有两个:

  • 创建一个公开的仓库,以验证仓库所有者是你
  • 将工单状态Response修改为Open
To continue the registration process, please follow these steps:
                    # Create a temporary, public repository called https://github.com/xxx/OSSRH-91364 to verify github account ownership.
                    # *Edit this ticket* and set Status to Open.

If you do not own this github account, you must define a new groupId.
More info: https://central.sonatype.org/publish/requirements/coordinates/ and https://central.sonatype.org/faq/verify-ownership/

四、上传至中央仓库

官方验证完后会邮件回复你,通知你的中央仓库已激活,分别上传你项目的SNAPSHOT和release版本至指定地址

Congratulations! Welcome to the Central Repository!
io.github.xxx has been prepared, now user(s) xxxx.com can:
Publish snapshot and release artifacts to *s01.oss.sonatype.org*
Have a look at this section of our official guide for deployment instructions:
https://central.sonatype.org/publish/publish-guide/#deployment

Depending on your build configuration, your first component(s) might be released automatically after a successful deployment.
If that happens, you will see a comment on this ticket confirming that your artifact has synced to Maven Central.
If you do not see this comment within an hour or two, you can follow the steps in this section of our guide:
https://central.sonatype.org/publish/release/

1、上传SNAPSHOT版本(快照版本)

参考文档地址:OSSRH Guide - The Central Repository Documentation

流程:下载GPG签名工具->生成秘钥->配置settings.xml->配置pom.xml->上传

下载GPG签名工具:

下载地址:https://www.gnupg.org/download/index.html

命令生成秘钥:

 生成:
gpg --gen-key

 Real name: 名字(英文)
 Email address: 邮箱(自己的邮箱)
 You selected this USER-ID:
 "xxx[xxx@qq.com](mailto:xxx@qq.com)"
 Change (N)ame, (E)mail, or (O)kay/(Q)uit? o
 之后往下,会让你输入用户名和邮箱,还有一个Passphase(输入两次,务必牢记,建议先找个地方记下来,后续要用到)

查看公钥
gpg --list-keys
 
查询结果:
--------------------------------------------------
pub   rsa2048 2021-02-02 [SC] [expires: 2023-02-02]
      453294371E0A38D70216B1E527EDC1D957E41325
uid           [ultimate] xxxxx <xxxxx@qq.com>
sub   rsa2048 2021-02-02 [E] [expires: 2023-02-02]


pub就是公钥:453294371E0A38D70216B1E527EDC1D957E41325
    
发布公钥:
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 453294371E0A38D70216B1E527EDC1D957E41325

查询发布公钥是否成功
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 453294371E0A38D70216B1E527EDC1D957E41325
 
成功的话会有如下结果
gpg: key 27EDC1D952E45891: "xxxxxx <xxxxx@qq.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

配置settings.xml

配置本地maven的配置文件

  <servers>
	  <server>
        <id>ossrh</id>
        <username>xxxx@qq.com(SonaType账号)</username>
        <password>填你注册SonaType时填写的密码</password>
	  </server>
  </servers>
 
  <profiles>
    <profile>
      <id>ossrh</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <!--这里填你安装的GnuPG位置-->
        <gpg.executable>/usr/local/MacGPG2/bin/gpg</gpg.executable>
        <gpg.passphrase>填写你生成秘钥时输入的密码</gpg.passphrase>
        <!--这里填你秘钥在磁盘上的位置,可通过上面步骤的 gpg --list-keys找到-->
        <gpg.homedir>C:/Users/laohan/.gnupg</gpg.homedir>
      </properties>
    </profile>
  </profiles>

配置Pom.xml

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- 此处配置的名称要和maven配置文件对应的serverId一致 -->
        <github.global.server>github</github.global.server>
    </properties>

    <dependencies>
        <!--自家项目依赖-->
    </dependencies>

    <!--gav信息-->
    <groupId>io.github.lindaifeng</groupId>
    <artifactId>auto-sensitive</artifactId>
    <!--需要特别注意,你上传的是SNAPSHOT仓库,所以此处版本号后缀必须带SNAPSHOT-->
    <version>1.0.0-SNAPSHOT</version>

    <!--项目信息...-->
    <name>auto-sensitive</name>
    <description>data sensitive</description>
    <url>https://github.com/lindaifeng/auto-sensitive</url>

    <!--开源协议...-->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <!--开发者信息-->
    <developers>
        <developer>
            <id>qingfeng</id>
            <name>qingfeng</name>
            <email>xxxx@qq.com</email>
            <roles>
                <role>Project Manager</role>
                <role>Architect</role>
            </roles>
            <timezone>+8</timezone>
        </developer>
    </developers>

    <!--项目在github或其它托管平台的地址-->
    <scm>
        <connection>https://github.com/lindaifeng/auto-sensitive.git</connection>
        <developerConnection>scm:git:ssh://git@github.com:lindaifeng/auto-sensitive.git</developerConnection>
        <url>https://github.com/lindaifeng/auto-sensitive</url>
    </scm>

    <profiles>
        <profile>
            <!--注意,此id必须与setting.xml中指定的一致,不要自作聪明改它名字-->
            <id>ossrh</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <!--发布到中央SNAPSHOT仓库插件-->
                <plugins>
                    <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>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>

                    <!--生成源码插件-->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.2.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!--生成API文档插件-->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <!--忽略非标准javadoc注释-->
                                    <additionalparam>-Xdoclint:none</additionalparam>
                                 <!--自己本地的jdk安装路径中javadoc路径-->    <javadocExecutable>/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin/javadoc</javadocExecutable>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!--gpg插件-->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </build>

            <distributionManagement>
                <snapshotRepository>
                    <!--注意,此id必须与setting.xml中指定的一致-->
                    <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>
        </profile>

    </profiles>

尝试maven打包 clean package

build success则可以上传,有报错则根据错误信息解决错误

上传项目

通过maven打包clean,deploy 弹出对话框输入生成gpg时填写的密码,success则上传成功。

​ 浏览器访问Nexus Repository Manager,登录查看你的maven项目

​ 快照仓库查看:https://s01.oss.sonatype.org/content/repositories/snapshots

2、上传release版本(稳定版本)

流程和上传SNAPSHOT步骤一致,下面仅说明差异点:

保持SNAPSHOT原样,修改如下内容即可:

修改:settings.xml

<!--将原来server标签和profile标签中的的ossrh替换为release-->
<id>release</id>

修改:Pom.xml

<!--修改GAV中的版本号,把SNAPSHOT后缀去掉-->
<version>1.0.0</version>
 
<!--将原来server标签和profile标签中的的ossrh替换为release-->
<id>release</id>
                <!--移除发布到中央SNAPSHOT仓库插件:nexus-staging-maven-plugin,并替换为发布到中央release仓库的插件:maven-release-plugin-->
                    <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>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
 
                    <!--替换为-->

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-release-plugin</artifactId>
                        <version>2.5.3</version>
                        <configuration>
                            <autoVersionSubmodules>true</autoVersionSubmodules>
                            <useReleaseProfile>false</useReleaseProfile>
                            <releaseProfiles>release</releaseProfiles>
                            <goals>deploy</goals>
                        </configuration>
                    </plugin>

发布:release

上面执行完成之后,登陆nexus:https://s01.oss.sonatype.org/#stagingRepositories,登上jira账号之后就能看到我们刚刚发布的内容

image-20230506165540292

​ 选中后点击上方的Close,他会检测你的jar包是否存在问题,如果存在问题,点击下方的Activity即可查看具体的问题或者发送邮件给你了,主要影响release的问题大部分都是打包时漏了一些东西,照着问题修复即可。

(轻微问题不修复也可以release)

检测完成后上方的release就会变成可点击的状态,点击release后,你会收到一份邮件:

大致内容为你的稳定版仓库已激活,大约30分钟后你能在中央仓库搜索到依赖

Central sync is activated for io.github.lindaifeng. After you successfully release, your component will be available to the public on Central https://repo1.maven.org/maven2/, typically within 30 minutes, though updates to https://search.maven.org can take up to four hours.

最后你就可以通过maven坐标直接引用你的项目依赖了

常见报错问题:

Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

解决方案:需要指定javadoc路径

<!--生成API文档插件-->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9.1</version>
    <executions>
      <execution>
        <id>attach-javadocs</id>
        <goals>
        <goal>jar</goal>
        </goals>
        <configuration>
        <javadocExecutable>/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin/javadoc</javadocExecutable>
        </configuration>
      </execution>
    </executions>
  </plugin>

报错File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!

解决方案:指定项目编码

在pom.xml文件中加入以下配置

 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>

错误: 未知标记:@ Author

解决方案:配置非标准javadoc注释

<!--忽略非标准javadoc注释-->
 <configuration> 
 	<additionalparam>-Xdoclint:none</additionalparam>
 </configuration>

提示403:Received status code 403 from server: Forbidden

可能是因为group id不正确

修改域名为申请Maven 时填写的域名。

提示400:Received status code 400 from server: Bad Request

可能是想要上传的版本号在Maven仓库中已存在了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/495956.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

USB HS-PHY眼图调试

1 USB2 PHY AFE 1.1 USB 2.0 FS PHY github ultraembedded / core_usb_fs_phy NOP USB transceiver for all USB transceiver which are either built-in into USB IP or which are mostly autonomous. 1.2 电阻参数 USB host端&#xff1a;D和D-各接一个15kΩ的下拉电阻&#…

数据结构学习记录——堆的建立(最大堆的建立、思路图解、代码实现、代码解释)

目录 最大堆的建立 方法1 方法2 思路图解 代码实现 代码解释 PercDown BuildHeap 最大堆的建立 建立最大堆&#xff1a;将已经存在的N个元素按最大堆的要求存放在一个一维数组中。 方法1 通过插入操作&#xff0c;将N个元素一个一个地插入到一个初始为空的堆中去。…

CSA发布|《洞察2022 云上数据安全与重要事项 》

云安全联盟大中华区就云上数据安全和重要事项的洞察和建议等相关问题展开调查并发布《洞察2022 云上数据安全与重要事项 》&#xff08;以下简称《报告》&#xff09;。报告的主要内容是关于云上数据安全和重要事项的洞察和建议。它包括了对云安全现状的分析、云安全风险的评估…

git的学习

文章目录 一、Git 的简介二、Git 工作流程三、Git 工作区、暂存区和版本库总结 一、Git 的简介 Git 是一个开源的分布式版本控制系统&#xff0c;用于敏捷高效地处理任何或小或大的项目。 Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软…

【c语言】字符串比较 | API仿真

创作不易&#xff0c;本篇文章如果帮助到了你&#xff0c;还请点赞 关注支持一下♡>&#x16966;<)!! 主页专栏有更多知识&#xff0c;如有疑问欢迎大家指正讨论&#xff0c;共同进步&#xff01; 给大家跳段街舞感谢支持&#xff01;ጿ ኈ ቼ ዽ ጿ ኈ ቼ ዽ ጿ ኈ ቼ …

RabbitMQ可靠性消息发送(java实现)

本博客属于 《RabbitMQ基础组件封装—整体结构》的子博客 一、整体架构 step1&#xff1a;消息落库&#xff0c;业务数据存库的同时&#xff0c;也要将消息记录存入数据库&#xff0c;二者要保证原子性&#xff1b; step2&#xff1a;Producer发送消息到MQ Broker&#xff1b…

Formik使用详解

Formik使用详解 1 引言 在现代Web应用程序中&#xff0c;表单是一种不可避免的输入机制&#xff0c;但是处理表单的过程可能会变得非常复杂。Formik是一个React表单库&#xff0c;它的目标是简化表单处理的过程。本文将介绍Formik的主要功能和用途&#xff0c;以及如何使用它来…

怎么成为一名架构师?架构师第一步。基层开发人员逆袭成为架构师真的很难吗?

文章目录 写在前面一、企业需要什么样的架构师1、从招聘软件上了解2、架构师的主要职责与能力 二、成为一名架构师很难吗1、架构师的定义2、当前大部分开发团队的现状3、为什么要有架构师4、技术人员如何自我突破 三、晨钟暮鼓的几句话 写在前面 一个团队中&#xff0c;每个人…

JAVA基础:Scanner类中next(), nextLine(), hasNext(), hasNextLine()

一、next() : 只读缓冲区中空格之前的数据,并且光标指向本行。二、nextLine() : 读取除回车以外的所有符号(整行内容)&#xff0c;光标定位在下一行三、hasNext() &#xff1a;检查下一个标记&#xff08;token&#xff09;&#xff0c;也就是以空格、制表符或换行符为分隔符的…

[JAVA EE]创建Servlet——实现Servlet接口笔记1

创建Servlet的方式之一&#xff1a;实现servlet接口 servlet的生命周期&#xff1a; 1、实例化&#xff1a;创建servlet实例对象 2、初始化&#xff1a;调用init方法完成初始化工作 3、服务&#xff1a;调用service方法来处理用户请求 4、销毁&#xff1a;调用destroy方法…

Java算法比赛常用方法

1. 开方&#xff1a;Math.sqrt(x); 2. x的a方&#xff1a;Math.pow(x,a); 3. 绝对值&#xff1a;Math.abs(x)&#xff1b; 4. BigInteger&#xff1a;大数&#xff08;加&#xff0c;减&#xff0c;乘&#xff0c;除&#xff0c;取余&#xff09; c.add(d) ; c.subtract(d)…

如何用100天彻底学会Python?

Python 是一门功能强大、易于学习且历史悠久的编程语言。如果你希望在短时间内彻底学会 Python&#xff0c;需要制定一个全面的学习计划&#xff0c;并进行刻意的练习和实践。 以下是一份建议的学习计划&#xff0c;帮助你在 100 天内掌握 Python 技能。 第 1-10 天&#xff…

从bootamition出发分析OpenHarmony下Gralloc buffer管理机制

从bootamition出发分析OpenHarmony下Gralloc buffer管理机制 引言 这个文档主要记录从bootamition角度出发&#xff0c;分析OpenHarmony下对gralloc buffer的管理&#xff01;由于OpenHarmony图形子系统过于复杂&#xff0c;且个人由于能力有限&#xff0c;这里我仅从gralloc b…

2023.03青少年机器人技术等级考试理论综合试卷(五级)

2023年3月青少年机器人技术等级考试理论综合试卷&#xff08;五级&#xff09; 一、单选题(共 20 题&#xff0c;共 80 分) 1. 0x35 & 7 的结果是&#xff1f;&#xff08;A &#xff09; A. 5 B. 55 C. 50 D. 54 2.一般状况下&#xff0c;关于主控板的工作电压&#xff0c…

「 Redis 」大key对持久化有什么影响?

「 Redis 」大key对持久化有什么影响&#xff1f; 参考&鸣谢 Redis 大 Key 对持久化有什么影响&#xff1f; XiaoLinCoding 解决了Redis大key问题&#xff0c;同事们都夸他牛皮 大白斯基 快手面试官&#xff1a;Redis变慢了&#xff0c;如何快速排查&#xff1f; Java 那些…

Vue 2.0 学习笔记

Vue学习笔记 文章目录 Vue学习笔记[toc]一、数据代理实现二、事件相关1.事件修饰符2.键盘事件 三、计算属性与监视1.计算属性-computed2.监视-watch 四、条件渲染1.v-show2.v-if&#xff0c;v-else-if 五、循环遍历1.v-for语法2.key的作用与原理 六、内置指令1.v-cloak指令&…

使用GitHub分享项目

一、注册账户 访问GitHub网站&#xff0c;点击“Sign up”按钮开始注册账号。然后按照提示输入你的用户名、电子邮箱地址和密码&#xff0c;提交成功后通过邮箱或你注册的手机号码进行验证身份。 二、上传项目 想分享自己的项目&#xff0c;首先需要在GitHub上创建一个新的仓库…

React + ts学习笔记

前提准备&#xff1a; 环境配置 安装node.js 官网安装&#xff1a;当前使用版本18.15.0 安装新的react应用&#xff1a; 运行命令新建react-app npx create-react-app study-ts-app当前版本&#xff1a; “react”: “^18.2.0”,“react-dom”: “^18.2.0”, 如果出现如…

优维低代码实践:第一个微应用

优维低代码技术专栏&#xff0c;是一个全新的、技术为主的专栏&#xff0c;由优维技术委员会成员执笔&#xff0c;基于优维7年低代码技术研发及运维成果&#xff0c;主要介绍低代码相关的技术原理及架构逻辑&#xff0c;目的是给广大运维人提供一个技术交流与学习的平台。 优维…

vue-element-admin踩坑合集+完整包(项目源码 +依赖)

目录 Nodejs版本&#xff1a; 安装依赖时遇到的报错&#xff1a; 启动报错&#xff1a; vue-element-admin完整包地址&#xff1a; 在部署安装使用vue-element-admin开源项目的时候&#xff0c;会遇到各种各样的问题。 这里是本人遇到的一些坑。。。。。。 Nodejs版本&am…