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

MavenCentral库发布记录

最近发布了 Android 路由库 URouter,支持 AGP8、ActivityResult启动等特性。
把提交到 Maven Central 过程记录一下。

一、注册 Sonatype 账号,新建项目

注册
https://​​issues.sonatype.org

登录后,新建项目:

相关选项,选择:

  • 项目:Community Support - Open Source Project - Repository Hosting (OSSRH)
  • 类型:New Project
  • 概要:填写 Git 项目名即可
  • Group Id: Github项目,io.github.xxx 用户名
  • Project URL: 填写 github 项目主页
  • SCM url: 填 github项目地址 + .git

在这里插入图片描述
在这里插入图片描述

点击提交后,等待 3-5分钟 回复,验证 github 所有权。

  • 在自己项目里,在 github 创建 回复的 仓库
  • 创建完成后,回复评论,大概意思就是即可: 仓库已创建

在这里插入图片描述

等待5-10分钟后,验证成功

这时候,就有上传到 sonatype nexus 仓库权限了

二、准备 GPG 密钥

GPG 来生成 密钥,安装 GPG
Windows下使用scoop安装:

scoop install gpggpg --generate-keygpg --list-keys

这里获取到pub公钥,

在这里插入图片描述

创建完成,–list-keys 显示 pub 第二方 一串:
67E95C8F2931C822********************F7E9
后面用于 上传和验证 公钥

上传公钥

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 
67E95C8F2931C822********************F7E9# 验证是否上传功能,后 8 位即可
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys ****F7E9

导出密钥,后面签名用

gpg --export-secret-keys 67E95C8F2931C822********************F7E9 > secret.gpg

三、Gradle项目配置

本地发布和远程发布,需要 maven-publish 插件,
GPG为了签名,需要 signing 插件。项目模块 build.gradle 配置:

plugins {id 'maven-publish'id 'signing'
}

添加后,gradle 就多了 publish 任务:

在这里插入图片描述

配置发布

添加maven-publish后,开始配置 publishing 代码块

// 配置发布后 groupId,默认 artifactId 是项目模块名
group = 'org.example'
version = '1.0'task sourcesJar(type: Jar) {classifier = 'sources'from sourceSets.main.allSource
}task javadocJar(type: Jar) {classifier = 'javadoc'from javadoc.destinationDir
}publishing {publications {release(MavenPublication) {// 配置POM信息pom {name = project.namedescription = 'xxx'url = 'https://github.com/xxx/xxx'// 开源协议licenses {license {name = 'The Apache License, Version 2.0'url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'}}// 配置开发者信息developers {developer {id = 'xxx'name = 'xxx'email = 'xxx@163.com'}}// scmscm {connection = 'https://github.com/xxx/xxx.git'developerConnection = 'https://github.com/xxx/xxx.git'url = 'https://github.com/xxx/xxx'}}// 发布文档 JARartifact javadocJar// 发布源码 JARartifact sourcesJarfrom components.java}}repositories {maven {url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"credentials {                username project.sonaUsername // sonatype usernamepassword project.sonaPassword // sonatype password}}}
}signing {sign publishing.publications.release
}

配置 sonatype 账号 和 GPG密钥

上面配置,还不能直接使用,在 gradle.properties 配置用到的 变量:

对于密码信息,可以放到 用户目录下的 gradle.properties,
Windows下是:

C:\Users\用户名\.gradle\gradle.properties

添加 账号信息:

# sonatype 账号信息
sonaUsername=xxxx
sonaPassword=xxxx
# GPG Signing Info
signing.keyId=XXXXXXXX
signing.password=xxxxxx
# 上面导出的 GPG 密钥路径
signing.secretKeyRingFile=C:\\Users\\username\\.gpg\\secret.gpg

四、发布到仓库

项目下执行命令进行发布:

.\gradlew.bat publish

发布成功后,进入 snoatype nexus 后台,管理发布:
https://s01.oss.sonatype.org/#stagingRepositories

在这里插入图片描述

  1. 在 Staging Repositories,勾选发布的仓库,点击Close并确定
  2. 稍等几分钟,验证通过,点 Release
  3. 10-30分钟后,会在 Maven Central 同步更新
  • 可在 https://mvnrepository.com/ 搜索查看库

文档

  • Android 发布: https://developer.android.com/build/publish-library/upload-library
  • https://blog.51cto.com/u_12853553/5896541
http://www.lryc.cn/news/154421.html

相关文章:

  • 小程序进阶-env(safe-area-inset-bottom)的使用
  • 移动端App持续集成体系构建实战
  • Mybatis的关联关系配置一对一,一对多,多对多的映射关系
  • 计算机竞赛 基于深度学习的中文情感分类 - 卷积神经网络 情感分类 情感分析 情感识别 评论情感分类
  • 时序预测 | MATLAB实现CNN-BiGRU卷积双向门控循环单元时间序列预测
  • [Rust GUI]0.10.0版本iced代码示例 - progress_bar
  • 使用vue-pdf出现的卡顿,空白,报错,浏览器崩溃解决办法
  • (笔记七)利用opencv进行形态学操作
  • Spring是什么?
  • 电梯SIP-IP五方对讲管理系统
  • leetcode283移动零
  • Docker 部署SpringBoot项目,使用外部配置文件启动项目
  • 电子半导体行业电能质量监测与治理系统解决方案 安科瑞 许敏
  • pdfh5在线预览pdf文件
  • Java智慧工地大数据中心源码
  • 关于人工智能的担忧
  • JVM之强软弱虚引用
  • Python编程练习与解答 练习98:一个数是素数吗
  • vue3+ts+uniapp实现小程序端input获取焦点计算上推页面距离
  • 【2023集创赛】加速科技杯二等奖作品:基于ATE的电源芯片测试设计与性能分析
  • Java入坑之Robot类
  • spring-secrity的Filter顺序+自定义过滤器
  • leetcode 371. 两整数之和
  • Medium: Where to Define Qualified users in A/B testing?
  • POJ 3662 Telephone Lines 二分,最小化第k大的数
  • 【mybatis-plus进阶】多租户场景中多数据源自定义来源dynamic-datasource实现
  • vue3 async await
  • CLion远程Linux开发环境搭建及找不到Linux头文件的解决方法
  • Python综合案例(基本地图使用)
  • maven的scope总结