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

↘锁芯ラ 提交于 2019-12-20 10:23:15

问题


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


回答1:


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.




回答2:


If you call scala, you will get whatever scala version is installed on the path of your operating system.

If you call sbt console, you get the scala version configured in the sbt build (build.sbt) with all libraries that are used in the build already on the classpath.

See this answer for details.



来源:https://stackoverflow.com/questions/27192398/what-is-the-difference-of-running-scala-and-sbt-console

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!