sbt发布到oss中央仓库的配置

分享 未结
1 1 1 6
梦境迷离 25天前发布
收藏 点赞

Mac

1.注册oss中央仓库账号,创建jira,百度一堆,不再介绍

2.安装秘钥生成工具 brew install gpg2

3.生成秘钥 gpg --gen-key,查看秘钥id gpg --list-keys

4.上传 秘钥 gpg--keyserver hkp://pool.sks-keyservers.net --send-keys 秘钥的id

5.导出秘钥到本地

gpg -a --export-secret-keys id > /Users/userName/.sbt/gpg/secring.asc

gpg -a --export id > /Users/userName/.sbt/gpg/pubring.asc

6.增加插件支持

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")

7.build.sbt增加

//发布到中央仓库的配置
lazy val publishSettings = Seq(
  useGpg := false,
  pgpPublicRing := new File("/Users/UserNmae/.sbt/gpg/pubring.asc"),
  pgpSecretRing := new File("/Users/UserNmae/.sbt/gpg/secring.asc"),
  pgpPassphrase := sys.env.get("PGP_PASS").map(_.toArray),
  publishTo := {
    val nexus = "https://oss.sonatype.org/"
    if (isSnapshot.value)
      Some("snapshots" at nexus + "content/repositories/snapshots")
    else
      Some("releases" at nexus + "service/local/staging/deploy/maven2")
  },
  licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/")),
  publishMavenStyle := true,
  publishArtifact in Test := false,
  pomIncludeRepository := { _ => false },
  sonatypeProfileName := organization.value,
  credentials += Credentials(
    "Sonatype Nexus Repository Manager",
    "oss.sonatype.org",
    sys.env.getOrElse("SONATYPE_USER", "id"),
    sys.env.getOrElse("SONATYPE_PASS", "password")
  ),

  isSnapshot := version.value endsWith "SNAPSHOT",
  homepage := Some(url("https://github.com/jxnu-liguobin")),

  scmInfo := Some(
    ScmInfo(
      url("https://github.com/jxnu-liguobin/dlsrpc"),
      "scm:git@github.com:jxnu-liguobin/dlsrpc.git"
    ))
)

设置

lazy val root = Project(id = "dlsRpc", base = file(".")).settings(publishSettings)

点击头像,选择user token 创建新的access user token 替换build.sbt中credentials的 id password

8.sbt publishSigned

9.去oss评论jira,告诉他已经发布


回帖