Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Simple Build Tool Introduction

Simple Build Tool Introduction

SBT Talk at Bay Area Scala Enthusiasts' Meetup (10/10/2011 @ Foursquare SF)

1960db2a7f53964ed6737363d05ee0ff?s=128

Indrajit Raychaudhuri

October 16, 2011
Tweet

More Decks by Indrajit Raychaudhuri

Other Decks in Technology

Transcript

  1. SBT <<= (Build) { FTW } @indrajitr

  2. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) SBT • Build

    tool on Scala for building Scala-Java projects • Compliant with Maven's convention (mostly) • Basics done right • Easy to set up for simple projects (intrusive) • Shares a *lot* with Scala
  3. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Build Definitions •

    Simple: Quick DSL • Diabolical: Scala code (with embedded DSL) • And the shell rocks
  4. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Build Definitions <base>/*.sbt

    <base>/project/*.scala <base>/project/plugins.sbt <base>/project/plugins/*.(scala|sbt) ~/.sbt/plugins/*.(scala|sbt)
  5. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) build.sbt organization :=

    "net.liftweb" name := "lift-demo" version := "1.0" scalaVersion := "2.9.1" libraryDependencies ++= Seq("net.liftweb" %% "lift-webkit" % "2.4-M4", "org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "jetty")
  6. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) project/build.scala import sbt._

    object LiftBuild extends Build { lazy val projects: Seq[ProjectReference] = Seq(common, actor, json) lazy val framework = Project("lift-framework", file(".")).aggregate(projects) lazy val common = Project(“lift-common”, file(“core/common”)).settings(/*...*/) lazy val actor = Project(“lift-actor”, file(“core/actor”)).dependsOn(common).settings(/*...*/) lazy val json = Project("lift-json", file("core/json")) dependsOn(common % "test") //lazy val foo = Project("lift-foo", file("core/foo"), delegates = common :: Nil) }
  7. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) The Expression Reminder:

    Statement ≠ Expression Statement: val foo = bar + baz Expression: bar + baz
  8. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) The Expression The

    expression: organization <<= organization or normalizedName.identity Is a: Project.Setting[S] And <<= is thus: final def <<= (app: Initialize[S]): Setting[S] for: InputKey, SettingsKey
  9. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) The Emojis The

    ONE <<=
  10. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) The Emojis And

    the rest := += ++= <+= <++= ~= • Initialize ( := ) • Append ( += ++= <+= <++= ) • Update ( ~= )
  11. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Scoped Keys sealed

    trait Key[T] extends Scoped final class SettingKey[T] extends Key[T] with ScopedSetting[T] final class TaskKey[T] extends Key[T] with ScopedTask[T] final class InputKey[T] extends Key[InputTask[T]] with ScopedInput[T]
  12. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Examples name :=

    "lift-demo" name ~= formalize resolvers in GlobalScope += JavaNet2Repository scalacOptions ++= Seq("-encoding", "UTF-8") resolvers <++= isSnapshot { s => if (s) Seq(ScalaToolsSnapshots) else Nil } inceptionYear <<= inceptionYear ?? Some(2011) organization <<= organization or normalizedName.identity
  13. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Examples libraryDependencies <<=

    (libraryDependencies, scalaVersion) apply { (ld, sv) => ld :+ scalap(sv) }) libraryDependencies <+= (scalaVersion)(scalap) libraryDependencies <+= scalaVersion apply scalap scalacOptions /*in GlobalScope*/ in doc <++= (name in doc, version in doc) map (Seq("-doc-title", _, "-doc-version", _))
  14. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Settings are Scoped!

    def in(s: Scope): Result // ScopedSetting, ScopedTask, ScopedInput def in(p: Reference): Result def in(t: Scoped): Result def in(c: ConfigKey): Result def in(c: ConfigKey, t: Scoped): Result def in(p: Reference, c: ConfigKey): Result def in(p: Reference, t: Scoped): Result def in(p: Reference, c: ConfigKey, t: Scoped): Result def in(p: ScopeAxis[Reference], c: ScopeAxis[ConfigKey], t: ScopeAxis[AttributeKey[_]]): Result
  15. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Miscellaneous MOAR Emojis

    (in shell)! ~ + ++ ; ! < - Plugin, State, Life, Universe and everything else
  16. Bay Area Scala Enthusiasts Meeting #42 (10-10-11) Lost? Befriend ‘em

    •Defaults.scala •Keys.scala • IDE
  17. Exercise

  18. Questions?