Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference of running `scala` and `sbt console`?

Tags:

scala

sbt

What is the difference of running the scala shell in these different ways?

like image 610
se7entyse7en Avatar asked Nov 28 '14 16:11

se7entyse7en


People also ask

Why do we need sbt in Scala?

Besides managing your project, some build tools, including sbt, can automatically manage dependencies for you. This means that if you need to use some libraries written by others, sbt can automatically download the right versions of those libraries and include them in your project for you.

Does sbt require Scala?

sbt needs Scala jars to run itself since it is written in Scala. sbt uses that same version of Scala to compile the build definitions that you write for your project because they use sbt APIs. This version of Scala is fixed for a specific sbt release and cannot be changed.

What does sbt stand for Scala?

Language. You can use several different tools to build your Scala projects, including Ant, Maven, Gradle, and more.

What does sbt run do?

Runs the main class for the project in the same virtual machine as sbt. Creates a jar file containing the files in src/main/resources and the classes compiled from src/main/scala and src/main/java. Displays detailed help for the specified command.


1 Answers

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._ <console>: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.

like image 196
Erik Kaplun Avatar answered Sep 19 '22 19:09

Erik Kaplun