上传jar/aar包到MavenCentral需要注意的一些问题

1,005 阅读2分钟

前言

随着jcenter托管服务可能即将停止,将jar/aar包从jcenter迁移到MavenCentral势在必行,迫在眉睫。本文则主要讲解上传jar/aar包到MavenCentral需要注意的一些问题。

阅读本文前请确保你已经熟悉上传MavenCentral的流程和步骤,否则你可能不知道我在说什么,哈哈哈。如何上传本地jar/aar包到MavenCentral可参考MavenCentral发布指南Sonatype OSSRH publish guide

正文

com.github将不再是有效的Group Id前缀

以下语句引用自Central Repository Changelog

2021-04-01 - com.github.* is not supported anymore as a valid coordinate

com.github will no longer be supported as a valid groupId prefix. Github has announced that they will stop redirecting GitHub Pages sites from *.github.com to the *.github.io domain, and requested that coordinates for individual projects only use io.github prefixes from now on.

Current projects already using the com.github groupId in Central are not affected by this change.

我生硬的翻译一下就是:

2021-04-01 - com.github.* 不再支持作为有效坐标︎

com.github将不再支持作为有效的groupId 前缀。Github已经宣布 ,他们将停止重定向从*.github.com向 *.github.io域名的GitHub Pages 网页,并要求从现在开始各个项目的坐标只使用io.github前缀。

已在中央仓库使用com.github作为groupId的当前项目不受此更改的影响。

因此我们在sonatype上创建问题时填写的Group Id应该为io.github.xxx,而不是com.github.xxx,而按照惯例Group Id往往是包名的前缀,因此我们Github上的项目包名尽量以io.github.xxx作为前缀。Group Id具体命名方式可参考官方文档

image.png

image.png

新的服务器s01.oss.sonatype.org

以下语句引用自Central Repository Changelog

2021-02-25 - New server s01.oss.sonatype.org

New projects will be allocated in the new server s01.oss.sonatype.org. Old projects using oss.sonatype.org instance are not affected by this change. 我生硬的翻译一下就是: 2021-02-25 -新服务器 s01.oss.sonatype.org︎ 新项目将分配在新服务器s01.oss.sonatype.org。使用oss.sonatype.org实例的旧项目不受此更改的影响。

因此我们有用到oss.sonatype.org的地方都应该改为s01.oss.sonatype.org,如上传MavenCentral对应的build.gradle脚本中上传地址应该更新为新地址,如下:

oss.sonatype.org/service/loc… -> s01.oss.sonatype.org/service/loc…

oss.sonatype.org/content/rep… -> s01.oss.sonatype.org/content/rep…

 repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") {
     authentication(userName: ossrhUsername, password: ossrhPassword)
 }

 snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") {
    authentication(userName: ossrhUsername, password: ossrhPassword)
 }