romanowski / hoarder   1.0.5


Project for cached compiation plugins for sbt

Scala versions: 2.12 2.10
sbt plugins: 1.0 0.13

Hoarder - don't repeat yourself when compiling!

Build Status Gitter room

Hoarder is the set of sbt plugins (for sbt 1.0.x and 0.13.x) that allows you to reuse compilation data from other workspaces (aka. Cached compilation).

Hoarder is based on zinc (from this PR).

The idea is simple: your code is compiled many times (e.g. during CI builds) and results are usually trashed. Instead, it's better to distribute classfiles (together with the cached compilation metadata) and don't repeat this work again and again.

Using caches will not make your local workspace read-only. Once a cache is imported, it will work exactly as locally compiled one (all following compilations will be normal, incremental ones).

Getting started

In order to use Hoarder in your project just add it as a standard sbt plugin (for a given project or globally):

addSbtPlugin("com.github.romanowski" % "hoarder" % "1.0.5")

Hoarder does not have any stable release so far, and you can track progress for sbt 0.13.x and 1.0.x

Integration with your project

Hoarder can be used in your project in multiple ways (workflows) described below. For now onlt few are supported but there's more to come (feel free to create issues with your own ideas).

Stash workflow

Stash workflow allows you to stash compilation results similarly to changes in git. Running stash task will store your current compilation data in a global directory for your project and later you can import that compilation using stashApply command. More can be found in docs.

The stash workflow can be useful to avoid recompilation in a gitlab-ci pipeline.

Cached PR verfication builds (e.g. Travis ones)

This workflow main goal is speed up of PR verification builds incrementally recompiling changes in PR.

There are 2 parts of this workflow: PR verification build (that use generated cached to speed up compilation) and build after PR is merged (that performs full compilaiton to be super safe and generate caches for future PR verification builds).

Hoarder allows anyone to define custom PR integration by providing new CachedCI.Setup instance.

Hoarder also provides predefine integrations e.g. for Travis. In order to use it (Travis one) all you need to do is:

  • create custom autoplugin with configuration in project that extends one of predefined flows e.g.
// project/CachedCi.scala

object CachedCi extends TravisPRValidation.PluginBase 
  • add cache definition to your build definition (usually.travis.yml file)
  - .hoarder-cache
  • add hoarder sbt preBuild and sbt postBuild tasks around your build commands, e.g.
- sbt preBuild 
- sbt <your-original-build-command>
- sbt postBuild

Minimal example configuration for ensime-server can be found in this PR.

More can be found in docs.

From release

Not implemented yet. See #2 for more details.

Cached compilation. How does it work?

Zinc incremental compiler (previously part of sbt) beside classfiles generates incremental compilation metadata that allows it later to recompile only the subset of classfiles. In this PR zinc was able to export that metadata in format that can be reused.