我有一个使用 SBT 的开源 Scala 项目,我想将我的库发布到 Maven。我该怎么做?
我总是忘记如何做到这一点。所以这是我的笔记:
一生中一次:
- Create Sonatype账户 https://issues.sonatype.org/secure/Signup!default.jspa
对于每台新的开发机器:
Install gpg
例如在 OSX 上:brew install gpg
Run gpg --gen-key
生成新密钥。记住您使用的密码和电子邮件.
-
确保在列出密钥时看到它:
> gpg --list-secret-keys
~/.gnupg/pubring.kbx
-----------------------------------
sec rsa2048 2019-06-13 [SC] [expires: 2021-06-12]
F5003E5C4718B1F466B244F766AA02EC8AA60DB9
uid [ultimate] Pathikrit Bhowmick <pathikritbhowmick@msn.com>
ssb rsa2048 2019-06-13 [E] [expires: 2021-06-12]
-
发布您的密钥:
> gpg --keyserver hkp://pool.sks-keyservers.net --send-keys F5003E5C4718B1F466B244F766AA02EC8AA60DB9
gpg: sending key 66AA02EC8AA60DB9 to hkp://pool.sks-keyservers.net
您还可以通过复制密钥来手动发布密钥
> gpg --armor --export F5003E5C4718B1F466B244F766AA02EC8AA60DB9
并在这里提交http://keyserver.ubuntu.com:11371/ http://keyserver.ubuntu.com:11371/
通过搜索验证密钥已发布gnupg.net http://keys.gnupg.net/pks/lookup?search=0xF5003E5C4718B1F466B244F766AA02EC8AA60DB9 or 密钥服务器网 https://sks-keyservers.net/pks/lookup?search=0xF5003E5C4718B1F466B244F766AA02EC8AA60DB9. 这可能需要一天的时间才能显示
-
Add default-key
给你的gpg.conf
:
> cat ~/.gnupg/gpg.conf
default-key F5003E5C4718B1F466B244F766AA02EC8AA60DB9
-
将以下内容附加到该文件(~/.sbt/${SBT_VERSION}/sonatype.sbt
):
credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", "<your username>", "<your password>")
对于每个新项目:
Create 使用您的 Sonatype 帐户请求新的存储库
等到上述问题 https://issues.sonatype.org/browse/OSSRH-18266?filter=-2已解决
-
Add sbt-pgp
, sbt-release
and sbt-sonatype
作为您项目的插件。这是一个例子插件.sbt https://github.com/pathikrit/better-files/blob/master/project/plugins.sbt:
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.5.1")
这是一个例子构建.sbt https://github.com/pathikrit/better-files/blob/master/build.sbt我用于多个项目。
对于每个新版本:
You may have to do export GPG_TTY=$(tty)
to let gpg
do password prompt in command line like below:
-
sbt +release
(将提示您输入您创建的密码gpg
)
- 注:
+release
跨您指定的交叉版本crossScalaVersions
。如果你有pushChanges
在您的构建中启用将您的提交推送到 git 远程,请确保您这样做pushChanges
只在最后一次crossVersion
.
查看工件于Sonatype https://oss.sonatype.org/content/repositories/releases/com/github/pathikrit/(快照版本是here https://oss.sonatype.org/content/repositories/snapshots/com/github/pathikrit/)。如果您在那里看不到它,您可以仔细检查Nexus 存储库管理器 https://oss.sonatype.org/#nexus-search;quick~better-files
等待几个小时让它传播到梅文中心 http://repo1.maven.org/maven2/com/github/pathikrit/
从头开始
- Sometime release may fail midway and your repository might be stuck in staging. You then have to go to https://oss.sonatype.org https://oss.sonatype.org > Login > Staging Repositories > Find your repo > Click Drop e.g.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)