lrytz / sbt-scala-module   2.2.0

Apache License 2.0 GitHub

sbt plugin for scala modules.

Scala versions: 2.12
sbt plugins: 1.0

Scala modules sbt plugin

This is an sbt 1.x plugin for building Scala modules.

What modules use it?

Why this plugin?

Having a shared plugin reduces duplication between the above repositories. Reducing duplication makes maintenance easier and helps ensure consistency.

A major feature of the plugin is automated tag-based publishing. A release is made by pushing a tag to GitHub. Travis-CI then stages artifacts on Sonatype. Pressing "Close" and "Release" in the Sonatype web UI will then send the artifacts to Maven Central.


Add the plugin to the project/plugins.sbt file:

addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.0.0")

Then, in your build.sbt add:

import ScalaModulePlugin._

scalaModuleSettings // in a multi-project build, you might want to apply these settings only to the
                    // main project (see e.g. scala-parallel-collections)

name         := "<module name>"
repoName     := "<GitHub repo name>" // the repo under, only required if different from name
organization := "<org>"              // only required if different from "org.scala-lang.modules"
version      := "<module version>"

// The plugin uses `scalaVersionsByJvm` to set `crossScalaVersions in ThisBuild` according to the JVM major version.
// The `scalaVersion in ThisBuild` is set to `crossScalaVersions.value.head`.
scalaVersionsByJvm in ThisBuild := {
  val v211 = "2.11.12"
  val v212 = "2.12.8"
  val v213 = "2.13.0-RC1"
  // Map[JvmMajorVersion, List[(ScalaVersion, UseForPublishing)]]
    8 -> List(v211 -> true, v212 -> true, v213 -> true),
    9 -> List(v211, v212, v213).map(_ -> false))

mimaPreviousVersion := Some("1.0.0") // enables MiMa (`None` by default, which disables it)

OsgiKeys.exportPackage := Seq(s"<exported package>;version=${version.value}")

// Other settings

These additional settings are enabled by scalaModuleSettings:

  • scalacOptions in (Compile, compile) ++= Seq("-feature", "-deprecation", "-unchecked", "-Xlint")
  • A file is generated and packaged
  • fork in Test := true to work around some classpath clashes with scala-xml
  • publishTo sonatype, credentials file expected in ~/.ivy2/.credentials
  • POM and OSGi metadata

The following settings are also available:

  • enableOptimizer adds -opt-inline-from:<sources> or -opt:l:project or -optimize to scalacOptions in (Compile, compile), depending on the Scala version
  • disablePublishing is useful for multi-project builds for projects that should not be published

Cutting a new release (of this plugin)

Release notes

Tag the release and add release notes to

Publishing via Bintray

  • Sign in to Bintray ( or create an "Open Source" account (

  • Check if you have a repository named sbt-plugins. If not, create it (Name: sbt-plugins, Type: Generic).

  • Make sure the current HEAD is a tagged revision. In sbt, version (set by sbt-git) should be according to a tag.

    > version
    [info] 2.3.4
  • Run publish in sbt. If you don't have a ~/.bintray/.credentials file, the sbt-bintray plugin will ask you for your username and API key. The API key can be obtained under "Edit Profile" ( The sbt-bintray plugin saves credentials to ~/.bintray/.credentials for future use.

  • If you haven't done so before, add your package for this plugin ( to the community sbt repository ( Otherwise you're done, the release is available.

    • Check if you added your package by searching for "sbt-scala-module" in the repository.
    • If you cannot find your package, click "Include My Package"
    • Search for your plugin (sbt-scala-module)
    • Click "Send" to send the request

The above instructions are a short version of