I have an open source Scala project using SBT and I would like to release my library to Maven. How do I do it?
Here's a quick overview of the steps we'll go through: Registering a Jira account with Sonatype, and verifying your ownership of the group ID you want to publish your artifact with. Generating a GPG key pair for signing your artifacts, publishing your public key, and exporting your private key.
The publishLocal action is used to publish your project to your Ivy local file repository, which is usually located at $HOME/. ivy2/local/ . You can then use this project from other projects on the same machine.
sbt resolver is the configuration for repository that contains jars and their dependencies. for example the below is a resolver definition for a repository called Sonatype and it points at snapshot releases (dev versions) resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
I always forget how to do this. So here are my notes:
Install gpg
e.g. on OSX: brew install gpg
Run gpg --gen-key
to generate a new key. Remember the passphrase and email you used.
Make sure you see it when you list your secret keys:
> gpg --list-secret-keys
~/.gnupg/pubring.kbx
-----------------------------------
sec rsa2048 2019-06-13 [SC] [expires: 2021-06-12]
F5003E5C4718B1F466B244F766AA02EC8AA60DB9
uid [ultimate] Pathikrit Bhowmick <[email protected]>
ssb rsa2048 2019-06-13 [E] [expires: 2021-06-12]
Publish your key:
> gpg --keyserver hkp://pool.sks-keyservers.net --send-keys F5003E5C4718B1F466B244F766AA02EC8AA60DB9
gpg: sending key 66AA02EC8AA60DB9 to hkp://pool.sks-keyservers.net
You can also publish your key manually by copy the key
> gpg --armor --export F5003E5C4718B1F466B244F766AA02EC8AA60DB9
And submitting it here http://keyserver.ubuntu.com:11371/
Verify that key got published by searching gnupg.net or keyserver.net. This may take up to a day to show up
Add default-key
to your gpg.conf
:
> cat ~/.gnupg/gpg.conf
default-key F5003E5C4718B1F466B244F766AA02EC8AA60DB9
Append following to this file (~/.sbt/${SBT_VERSION}/sonatype.sbt
):
credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", "<your username>", "<your password>")
Create new JIRA issue using your Sonatype account to request new repo
Wait till above issue is resolved
Add sbt-pgp
, sbt-release
and sbt-sonatype
as a plugin to your project. Here is an example 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")
Here is an example build.sbt that I use for multi-projects.
You may have to do export GPG_TTY=$(tty)
to let gpg
do password prompt in command line like below:
sbt +release
(will prompt for passphrase that you created for gpg
)
+release
cross releases across your specified crossScalaVersions
. If you have pushChanges
enabled in your build to push your commit to git remote, make sure you do pushChanges
once only on the last crossVersion
.View artifact on Sonatype (the snapshot versions are here). If you cannot see it there you can double check the Nexus Repository Manager
Wait few hours for it to propagate to Maven Central
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With