Skip to main content
Version: 2.x

ZIO SBT Ecosystem

ZioSbtEcosystemPlugin provides the settings, tasks and commands that are common to every ZIO project. It is an auto plugin with trigger = allRequirements, so having it on the classpath enables it. It requires the sbt-header, sbt-scalafix, sbt-scalafmt and sbt-buildinfo plugins, which come with it.

To install it, add addSbtPlugin("dev.zio" % "zio-sbt-ecosystem" % "0.8.13") to project/plugins.sbt, as described in Installation.

Settings​

The plugin defines these keys. The first seven are set at the ThisBuild level. welcomeBannerEnabled and usefulTasksAndSettings are set in each project.

SettingTypeDefaultDescription
scala212String"2.12.21"The Scala 2.12 version of the build
scala213String"2.13.18"The Scala 2.13 version of the build
scala3String"3.9.0"The Scala 3 version of the build
scalaVersionStringscala213.valueSet by the plugin, so a build compiles with Scala 2.13 unless it overrides this
crossScalaVersionsSeq[String]Seq(scala212, scala213, scala3)Set by the plugin
zioVersionString"2.1.22"The ZIO version that enableZIO adds as a dependency
javaPlatformString"17"The Java version passed to -source and -target and used for Scala compiler options
welcomeBannerEnabledBooleantrueWhether sbt prints the welcome banner with the list of useful commands on startup
usefulTasksAndSettingsMap[String, String]the lint, fmt, fix, prepare, quiet and publish-all commands and the strict-compile tasksName and description pairs that the welcome banner prints

The defaults of scala212, scala213, scala3 and zioVersion are baked into the version of the plugin, so upgrading the plugin changes them. Set zioVersion explicitly in every build:

ThisBuild / zioVersion := "2.1.22"
note

Don't rely on zioVersion's default. It's baked into whichever version of zio-sbt-ecosystem you depend on, so upgrading the plugin—including via an automated dependency-update PR—can silently change your project's own ZIO version along with it. Setting zioVersion explicitly keeps that a deliberate decision you make, not a side effect of a plugin bump. Every ZIO ecosystem project (zio-logging, zio-kafka, zio-cache, and others) already follows this practice.

The Scala version settings are plain String keys, so they can define crossScalaVersions or any other setting:

crossScalaVersions := Seq(scala212.value, scala213.value, scala3.value)

The plugin also sets these build-wide defaults: organization := "dev.zio", the Apache 2 licenses, homepage and scmInfo derived from the lower-cased project name (https://zio.dev/<name> and https://github.com/zio/<name>), the pgp* keys for signing, and onChangedBuildSource := ReloadOnSourceChanges.

Commands​

The plugin registers these sbt commands. Each one except quiet off first turns the welcome banner off.

CommandWhat it runs
fmtscalafmtSbt, then +scalafmt and +Test / scalafmt: formats the sources
lintenableStrictCompile, the cross-built scalafmt checks, scalafix --check, then disableStrictCompile
fixCompile / scalafix and Test / scalafix: applies the scalafix rules
prepareThe scalafmt formatting tasks, then fix: prepares the sources for a pull request
publish-allproject / then +publishSigned: signs and publishes all artifacts
quietquiet on mutes the welcome banner and quiet off shows it again

addCommand(commands, name, description) adds a command of your own that the welcome banner lists:

addCommand(List("scalafmtAll", "Test / compile"), "check-all", "Formats and compiles everything")

Tasks​

The plugin defines three tasks in zio.sbt.Tasks.

TaskDescription
enableStrictCompileSets the system property enable.strict.compilation to true
disableStrictCompileSets the system property enable.strict.compilation to false
buildRuns clean, enableStrictCompile, Compile / compile, Test / compile and Test / test, then disableStrictCompile

The plugin's own settings do not read the enable.strict.compilation property. stdSettings adds -Xfatal-warnings on Scala 2 when the CI environment variable is set, whatever the property says. A build that wants warnings as errors only under lint can read the property in its own scalacOptions.

Standard Settings​

stdSettings is the entry point for configuring a project. Its parameters are:

ParameterTypeDefaultDescription
nameOption[String]NoneSets the sbt name when present
packageNameOption[String]NoneEnables buildInfoSettings with this package for sbt-buildinfo when present
javaPlatformString"17"Sets the javaPlatform setting and the -source and -target javac options
enableKindProjectorBooleantrueAdds the kind-projector compiler plugin on Scala 2
enableCrossProjectBooleanfalseAdds crossProjectSettings
enableScalafixBooleantrueAdds scalafixSettings
turnCompilerWarningIntoErrorsBooleantrueAdds -Xfatal-warnings on Scala 2 when the CI environment variable is set

Besides these, stdSettings adds the standard scalacOptions for the Scala version, runs Test / parallelExecution on Scala 2 only, enables autoAPIMappings and adds the better-monadic-for compiler plugin.

stdSettings takes the project name and, optionally, the package name for build info:

lazy val core = project
.settings(stdSettings(name = Some("my-library"), packageName = Some("com.example.mylibrary")))

Dependency and Platform Settings​

These methods return sbt settings that a project adds with .settings(...).

MethodDescription
enableZIO(enableStreaming = false, enableTesting = true)Adds zio with zioVersion, plus zio-streams and the ZIO Test framework as requested
jsSettingsSettings for Scala.js projects: forks Test only on the JVM platform
nativeSettingsSettings for Scala Native projects: skips doc and replaces Test / test with a compile of the tests, and forks Test only on the JVM platform
scalajsAdds the -scalajs option on Scala 3
scalafixSettingsEnables semanticdb (except on Scala 3) and adds the scaluzzi scalafix rules
scalaReflectTestSettingsAdds scala-reflect in the Test configuration, from the Scala 2.13 version on Scala 3
crossProjectSettingsAdds the platform- and Scala-version-specific source directories (for example scala-2.13+, scala-3.x) to Compile and Test
buildInfoSettings(packageName)Exposes name, version, scalaVersion, sbtVersion and isSnapshot in sbt-buildinfo
macroExpansionSettingsEnables macro annotations on Scala 2.13 and the macro paradise plugin on 2.12
macroDefinitionSettingsAdds -language:experimental.macros and the provided scala-reflect and scala-compiler on Scala 2

enableZIO adds ZIO using zioVersion:

lazy val core = project
.settings(enableZIO(enableStreaming = true))

Version-Specific Helpers​

Each helper takes the Scala binary versions it applies to, such as "2.13" or "3", then the options or dependencies. The optionsOn* and dependenciesOn* methods return initializations and the add* methods return settings.

MethodDescription
optionsOn(versions*)(options*)The options when the Scala binary version is one of versions, an empty Seq otherwise
optionsOnExcept(versions*)(options*)The options when the Scala binary version is none of versions
optionsOnOrElse(versions*)(options*)(other*)The options on the listed versions and the other options everywhere else
addOptionsOn, addOptionsOnExcept, addOptionsOnOrElseThe same three, as a setting that appends to scalacOptions
dependenciesOn(versions*)(modules*)The modules when the Scala binary version is one of versions
dependenciesOnExcept(versions*)(modules*)The modules when the Scala binary version is none of versions
dependenciesOnOrElse(versions*)(modules*)(other*)The modules on the listed versions and the other modules everywhere else
addDependenciesOn, addDependenciesOnExcept, addDependenciesOnOrElseThe same three, as a setting that appends to libraryDependencies

addOptionsOn adds compiler options for the listed Scala binary versions only:

addOptionsOn("2.13")("-Ymacro-annotations")

ZIO Chat

Hi there! 👋 I'm ZIO Chat, your friendly neighborhood ZIO expert. I'm here to help you navigate the world of ZIO. Whether you're a seasoned pro or just starting out, fire away with your ZIO questions. I will hit you back with the best insights I've got. Let's dive into the world of ZIO together!