A working example of using a sbt AutoPlugin (scaladoc) to provide a build environment to run the Scala compiler's optimizer only for a production build.
This repo is based on BuildEnvPlugin from the sbt-native-packager docs.
See BuildEnvPlugin.scala and the usage of buildEnv
in build.sbt.
This repo includes a documented example of scalac optimizer options. Anecdotally I've observed compilation taking up to 5x longer when running the optimizer, but the resulting performance speedup was significant for me.
$ sbt run
👉 output of sbt run
includes "[info] Running in build environment: Development".
$ ENV=production sbt run
# or
$ sbt -Denv=production run
👉 output of ENV=production sbt run
includes "[info] Running in build environment: Production".
-
sbt-native-packager suggests using sbt submodules for staging and production builds. However in their example the staging and production builds depend on the same app build. They add configuration based on staging/production but the app build is unmodified. The example in this repo modifies the app build to include scalac optimizer options for a production build.
-
It's been suggested that an AutoPlugin is too heavy for this use case. I'd love to see a simpler solution that resides entirely within build.sbt.
- in my personal use of this plugin I found it necessary to include
scalaVersion := "2.12.10"
in myproject/plugins.sbt
so that the build of BuildEnvPlugin.scala was compatible with other plugins used viaaddSbtPlugin(...)
inproject/plugins.sbt
.