The document discusses using SBT archetype plugins to solve the problem of multiple build maintenance hell by standardizing build configurations across many projects through shared plugins, minimizing duplicate build code and maximizing consistency when upgrades are needed. It proposes implementing archetype plugins that projects can depend on to get standardized core settings, dependencies, and build logic while reducing typical project build file lines of code by over 95%.
Software Project Health Check: Best Practices and Techniques for Your Product...
Combatting Multiple Build Maintenance Hell with Archetype AutoPlugins
1. Composing Project
Archetypes with SBT
AutoPlugins
Mark Schaake
allenai.org
“contribute to humanity through high-impact AI research and engineering”
2. Composing Project
Archetypes with SBT
AutoPlugins
Mark Schaake
allenai.org
“contribute to humanity through high-impact AI research and engineering”
3. Combatting Multiple Build
Maintenance Hell with
Archetype AutoPlugins
Mark Schaake
allenai.org
“contribute to humanity through high-impact AI research and engineering”
4. “When you have very limited visibility and
control over many project builds to the point
where you feel paralyzed to maintaining cross-
project consistency.”
(Multiple Build Maintenance Hell)
MBMH
• visibility: what libraries, plugins, versions?
• control: how to enforce team standards, upgrades?
• consistency: minimize context switching
27. Other Considerations
• Archetype settings shared by similar projects
• Core settings common to all projects
• Formatting and Style
28. Other Considerations
• Archetype settings shared by similar projects
• Core settings common to all projects
• Formatting and Style
• Generate Git version resource
37. web-service 1.0 Svc A
Archetype Plugins Projects
Svc B
Svc C
Svc D
web-service 2.0
web-service 2.1
library 1.0
library 1.1
cli 1.0
Lib X
Lib Y
CLI Z
…
…
…
web-app 1.0 App W
…
38. web-service 1.0 Svc A
Archetype Plugins Projects
Svc B
Svc C
Svc D
web-service 2.0
web-service 2.1
library 1.0
library 1.1
cli 1.0
Lib X
Lib Y
CLI Z
…
…
…
web-app 1.0 App W
…
47. Adding Popular SBT Plugin
Settings
“To add the default plugin settings, add the
following to your build.sbt…”
48. Adding Popular SBT Plugin
Settings
“To add the default plugin settings, add the
following to your build.sbt…”
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._
packageArchetype.java_application
sbt-native-packager
org.scalastyle.sbt.ScalastylePlugin.Settings
sbt-scalastyle
scalariformSettings
sbt-scalariform
Revolver.settings
sbt-revolver
50. SBT AutoPlugins
• The new Plugin standard (since SBT 0.13.5)
• Well-defined plugin API
51. SBT AutoPlugins
• The new Plugin standard (since SBT 0.13.5)
• Well-defined plugin API
• Less need for conventions
52. SBT AutoPlugins
• The new Plugin standard (since SBT 0.13.5)
• Well-defined plugin API
• Less need for conventions
• Killer feature: can compose plugins via `requires`
53. abstract class AutoPlugin {
…
/** When this AutoPlugin is enabled, all required
* plugins will also be enabled automatically prior
* to enabling this AutoPlugin. */
def requires: Plugins = empty
/** The [[Setting]]s to add in the scope of each
* project that activates this AutoPlugin. */
def projectSettings: Seq[Setting[_]] = Nil
…
}
SBT AutoPlugins
https://github.com/sbt/sbt/blob/0.13.7/main/src/main/scala/sbt/Plugins.scala
72. Project Archetype Recipe
• Create a company “sbt-plugins” project
• Wrap third-party plugins (scalariform, scalastyle, etc.)
• Define a core settings AutoPlugin that enforces team
standards
• Define archetype plugins that require core settings
and add in archetype-specific settings
• Publish to Bintray and serve!