Hoarder - don't repeat yourself when compiling!
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).
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.2")
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 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.
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
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
projectthat extends one of predefined flows e.g.
// project/CachedCi.scala import org.romanowski.hoarder.actions.ci.TravisPRValidation object CachedCi extends TravisPRValidation.PluginBase
- add cache definition to your build definition (usually
cache: directories: - .hoarder-cache
- add hoarder
sbt postBuildtasks 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.
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.