Central Repository发布Scala包的完整流程与方法
时间:2026-08-21 | 作者:游戏探长 | 阅读:0什么是 Central Repository
The Central Repository is the largest collection of Ja va and other open-source components. It provides the easiest way to access and distribute your software components to millions of developers. It is the default repository for Apache Ma ven, SBT, and other build systems and can be easily used from Apache Ant/Ivy, Gradle, and many other tools.
Central Repositroy是最大的一个Ja va包仓库,还是Apache Ma ven, SBT的默认仓库。
什么是 Sonatype
Sonatype,一家位于马里兰州富尔顿的网络安全公司,致力于为企业提供关于开源组件和软件安全的精准情报
Sonatype是一家技术服务公司
Sonatype和Central Repository之间是什么关系
Sonatype serves as the steward, maintainer, and financial backer of the Central Repository, and is committed to continuously offering it to the community of component consumers and providers.
简单来说Sonatype是Central Repository的管理者和投资者
发布前要准备什么
-
这里最重要的字段是Group Id,通常它是一个域名,你必须要证明你拥有这个域名。如果你没有注册域名的话,也可以使用GitHub提供的域名io.github.(account),下面是我收到的关于域名的要求
如何发布
添加插件
在 project/plugins.sbt中添加下面的插件
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.9") // 管理Sonatype
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") // 管理gpg
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") // 管理发布流程
重写 release 任务
在 build.sbt中添加下面的代码
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining("+publishSigned"),
releaseStepCommand("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
pushChanges
)
创建 GPG 密钥
添加鉴权信息和密钥信息
- 新建文件
~/.sbt//sonatype.sbt - 在新建文件中添加如下代码
credentials += Credentials("Sonatype Nexus Repository Manager", "s01.oss.sonatype.org", "" , "" ) credentials += Credentials( "" , "gpg", "" , // key identifier "ignored" // this field is ignored; passwords are supplied by pinentry )
执行release进行发布
在sbt中执行 release
sbt> release
发布成功后我们就可以在 Central Repository看到我们的包啦












