Skip to content

Instantly share code, notes, and snippets.

@fbaierl
Last active November 3, 2018 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbaierl/10f16ad98fa4a65f08bde8b8a60e197c to your computer and use it in GitHub Desktop.
Save fbaierl/10f16ad98fa4a65f08bde8b8a60e197c to your computer and use it in GitHub Desktop.
How to release a Scala library to Maven Central using sbt?

Good resources:

Once in your life:

  1. Create Sonatype account

For every new developer machine:

  1. Install gpg e.g. on OSX: brew install gpg

  2. Run gpg --gen-key to generate a new key. Remember the passphrase and email you you used.

  3. List your key:

     > gpg --list-keys pathikritbhowmick@msn.com
    
     pub   rsa2048 2018-07-24 [SC] [expires: 2020-07-23]
           F5003E5C4718B1F466B244F766AA02EC8AA60DB9
     uid           [ultimate] Pathikrit Bhowmick <pathikritbhowmick@msn.com>
     sub   rsa2048 
    
     2018-07-24 [E] [expires: 2020-07-23]
    
  4. Publish your key:

     > gpg --keyserver hkp://pool.sks-keyservers.net --send-keys F5003E5C4718B1F466B244F766AA02EC8AA60DB9
    
     gpg: WARNING: server 'dirmngr' is older than us (2.2.7 < 2.2.9)
     gpg: Note: Outdated servers may lack important security fixes.
     gpg: Note: Use the command "gpgconf --kill all" to restart them.
     gpg: sending key 66AA02EC8AA60DB9 to hkp://pool.sks-keyservers.net
    

You can verify the key got published by looking at: http://pool.sks-keyservers.net/pks/lookup?search=0x66AA02EC8AA60DB9

  1. Append following to this file (~/.sbt/${SBT_VERSION}/sonatype.sbt):

     credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", "<your username>", "<your password>")
    

For each new project:

  1. Create new JIRA issue using your Sonatype account to request new repo

  2. Wait till above issue is resolved

  3. 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")
    
  4. Here is an example build.sbt that I use for multi-projects.

For each new release:

  1. sbt +release (will prompt for passphrase that you created for gpg)
  2. Note: The +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.
  3. View artifact on Sonatype (the snapshot versions are here)
  4. Wait few hours for it to propagate to Maven Central
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment