Skip to content

Scala example of using a sbt AutoPlugin to provide a build environment and optimize only the production build.

License

Notifications You must be signed in to change notification settings

ryanberckmans/sbt-optimize-prod-with-build-env-plugin-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sbt-optimize-prod-with-build-env-plugin-example

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.

Running it

$ sbt run

👉 output of sbt run includes "[info] Running in build environment: Development".

Running a production build

$ ENV=production sbt run
# or
$ sbt -Denv=production run

👉 output of ENV=production sbt run includes "[info] Running in build environment: Production".

Potential alternative to the plugin approach in this repo

  1. 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.

  2. 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.

Troubleshooting

  • in my personal use of this plugin I found it necessary to include scalaVersion := "2.12.10" in my project/plugins.sbt so that the build of BuildEnvPlugin.scala was compatible with other plugins used via addSbtPlugin(...) in project/plugins.sbt.

About

Scala example of using a sbt AutoPlugin to provide a build environment and optimize only the production build.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages