What is the difference of running the scala shell in these different ways?
SBT is tied to a specific project defined by a build.sbt
file in a way that $ sbt console
will load up the same REPL environment as $ scala
but with the addition of all of the project code and dependencies defined in the build available for import. Also, it will use the version of Scala defined by build.sbt
.
For example:
$ scala
scala> import scalaz._
:7: error: not found: value scalaz
import scalaz._
but with this build.sbt
:
scalaVersion := "2.11.4"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0"
the import succeeds:
$ sbt console
...
scala> import scalaz._
import scalaz._
The command loads Scala 2.11.4 instead of the system wide Scala (or any version of it on PATH
).
Furthermore, invoking sbt console
after adding new items in the build’s libraryDependencies
will fetch them.