Skip to main content
Version: 2.x

Check Scaladoc Examples in CI

Code examples in Scaladoc comments are not compiled with the code, so they break silently when a method is renamed or a signature changes. ZIO SBT Scaladoc compiles them, and ZIO SBT CI can run it on every pull request. This guide turns both on.

1. Add the Pluginโ€‹

Add the plugin to project/plugins.sbt:

addSbtPlugin("dev.zio" % "zio-sbt-scaladoc" % "0.8.13")

It turns itself on in every module of the build.

2. Run the Check Locallyโ€‹

sbt +scaladocCheck

This compiles the examples of every module on every Scala version it builds, and on every platform (JVM, Scala.js, Scala Native) the build has. To check one module on the current Scala version, run sbt core/scaladocCheck.

Fix what fails. A failure points at the Scaladoc line. For a block that only works on some versions or platforms, add a marker as its first line, such as // scala-3-only or // jvm-only; for one that cannot compile on its own, add // no-check: <reason>. The reference lists every marker.

3. Turn On the CI Stepโ€‹

Set ciCheckScaladocExamples next to the other ci* settings in build.sbt:

ThisBuild / ciCheckScaladocExamples := true

Then regenerate the workflows:

sbt ciGenerateGithubWorkflow

The build job of ci.yml gains one step, after "Check artifacts build process":

- name: Check Scaladoc examples
run: sbt --no-colors +scaladocCheck

Commit the build change and the regenerated ci.yml together.

Optional: Leave a Module Outโ€‹

To skip a module, such as benchmarks or examples:

lazy val benchmarks = project
.settings(scaladocCheck / skip := true)

Optional: A Library Only the Examples Useโ€‹

When an example needs a library its module does not depend on, add it to the ScaladocCheck configuration. The published module does not depend on it:

lazy val core = project
.settings(libraryDependencies += "dev.zio" %% "zio-streams" % "2.1.27" % ScaladocCheck)

ZIO Chat

๐ŸŒŸ Greetings from ZIO Chat! ๐ŸŒŸ Have questions about ZIO? Look no further! I'm here to be your ZIO guru. Whether you're a seasoned pro or just starting out, I've got answers tailored just for you. Fire away with your ZIO queries, and I'll hit you back with the best insights I've got. Let's dive into the world of ZIO together!