Aliases
> alias q = exit
> alias r = last
> alias \!/ = compile
| space, → | next slide |
| ← | previous slide |
| d | debug mode |
| ## <ret> | go to slide # |
| c | table of contents (vi) |
| f | toggle footer |
| r | reload slides |
| z | toggle help (this) |
Brian Clapper, bmc@ardentex.com
ArdenTex, Inc.
PHASE Meeting: 18 October, 2011
build.sbt build file
build.sbt todaybuild.sbtbuild.sbt)project/build.scala*.scala under project gets compiledbuild.scala for multiproject projects.build.sbtbuild.sbt SettingsSetting[T] produces values of type TSetting objectsbuild.sbt Settingseval - evaluate an expressioninspect - inspect a task or setting and its dependencies
show - run a task and show its outputlast - run the last command~ watch and repeat+ run against cross version++ run against all cross versions"junit" % "junit" % "4.8" % "test"> alias q = exit
> alias r = last
> alias \!/ = compile
key in scope bind (dependencies) value
bind is a binding method.
libraryDependencies <<= libraryDependencies apply {
(deps: Seq[ModuleID]) =>
// Note that :+ is a method on Seq that appends a single value
deps :+ ("junit" % "junit" % "4.8" % "test")
}
Or just:
libraryDependencies <<= libraryDependencies apply { deps =>
// Note that :+ is a method on Seq that appends a single value
deps :+ ("junit" % "junit" % "4.8" % "test")
}
:= defines a setting that overwrites any previous value without referring
to other settings.
Define a setting that will set name to "My Project", regardless of whether
name has already been initialized:
name := "My Project"
No other settings are used. The value assigned is just a constant.
+= defines a setting that appends a single value to the current sequence,
without referring to other settings.
Define a setting that append a JUnit dependency to libraryDependencies.
libraryDependencies += "junit" % "junit" % "4.8" % "test"
The dependency DSL should be familiar from sbt 0.7.
The libraryDependencies setting is used by many built-in tasks.
++= is similar to +=
Appends a sequence to the current sequence, without using other settings
Define a setting that will add dependencies on ScalaCheck and specs to the current list of dependencies:
libraryDependencies ++= Seq(
"org.scala-tools.testing" %% "scalacheck" % "1.9" % "test",
"org.scala-tools.testing" %% "specs" % "1.6.8" % "test"
)
Direct from the sbt wiki:
The types involved in += and ++= are constrained by the existence of an
implicit parameter of type Append.Value[A,B] in the case of += or
Append.Values[A,B] in the case of ++=. Here, B is the type of the
value being appended and A is the type of the setting that the value is
being appended to. See Append for the provided instances.
Clear?
~= transforms the current value of a setting.
Defines a setting that will remove -Y compiler options from the current
list of compiler options.
scalacOptions in Compile ~= { (options: Seq[String]) =>
options filterNot ( _ startsWith "-Y" )
}
Thus, the earlier declaration of JUnit as a library dependency using +=
could also be written as:
libraryDependencies ~= { (deps: Seq[ModuleID]) =>
deps :+ ("junit" % "junit" % "4.8" % "test")
}
<<= is the most general binding method.
Defines a setting using other settings, possibly including previous values of the setting being defined.
All others can be implemented in terms of <<=
Declare JUnit as a dependency using <<=:
libraryDependencies <<= libraryDependencies apply { deps =>
deps :+ ("junit" % "junit" % "4.8" % "test")
}
<+= is a convenience hybrid of += and <<=.
Add a dependency on the Scala compiler to the current list of dependencies.
Because the scalaVersion setting is used, the method is <+=, not +=
libraryDependencies <+= scalaVersion(
"org.scala-lang" % "scala-compiler" % _
)
<++= is a convenience hybrid of ++= and <<=.
Add a dependency on the Scala compiler to the current list of dependencies.
Because another setting (scalaVersion) is used and a Seq is appended,
use <++=
libraryDependencies <++= scalaVersion { sv =>
("org.scala-lang" % "scala-compiler" % sv) ::
("org.scala-lang" % "scala-swing" % sv) ::
Nil
}
project/plugins/build.sbt(cut to Emacs session...)
Example used is: https://github.com/bmc/grizzled-scala/blob/master/build.sbt