Skip to content

Instantly share code, notes, and snippets.

@fdietze
Last active June 26, 2020 12:47
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fdietze/1c2d03c4e2321581cea2c0d84d345e03 to your computer and use it in GitHub Desktop.
Save fdietze/1c2d03c4e2321581cea2c0d84d345e03 to your computer and use it in GitHub Desktop.
Sbt Sonatype

Jitpack

https://jitpack.io

For testing purposes, the easiest way to go is jitpack:

resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.User" % "Repo" % "Tag"

Sonatype

Create Account in Sonatype Issue tracker

https://issues.sonatype.org/projects/OSSRH

Create Issue with desired groupId

https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134

sonatype publishing

plugins.sbt

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.2")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")

build.sbt:

pgpSecretRing in Global := file("secring.gpg")
pgpPublicRing in Global := file("pubring.gpg")
pgpPassphrase in Global := Some("".toCharArray)

organization in Global := "com.github.bla"

pomExtra := {
  <url>https://github.com/organisation/repository</url>
  <licenses>
    <license>
      <name>Apache 2</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
  </licenses>
  <scm>
    <url>https://github.com/organisation/repository</url>
    <connection>scm:git:git@github.com:organisation/repository.git</connection>
  </scm>
  <developers>
    <developer>
      <id>dev1</id>
      <name>Full Name</name>
      <url>https://github.com/dev1</url>
    </developer>
    <developer>
      <id>dev2</id>
      <name>Full Name</name>
      <url>https://github.com/dev2</url>
    </developer>
  </developers>
}

generate key pair and send to keyserver

$ sbt "set pgpReadOnly := false" "pgp-cmd gen-key"
$ sbt "set pgpReadOnly := false" "pgp-cmd send-key aaaabbbbccccdddd http://pgp.mit.edu:11371"

Store Sonatype credentials in separate sbt file

sonatype.sbt

// this has to go in an sbt file because if we use an external
// credentials properties file it ignores it
credentials in Global += Credentials(
  "Sonatype Nexus Repository Manager",
  "oss.sonatype.org",
  "username",
  "password"
)

Add Keyrings and credentials to .gitignore, to not accidentally commit them

*.gpg
sonatype.sbt

Publish Snapshots

$ sbt ++publishSigned

Publish Releases

$ sbt ++publishSigned
$ sbt sonatypeReleaseAll

Nexus Repository Manager

https://oss.sonatype.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment