运行`scala`和`sbt console`有什么区别? [英] What is the difference of running `scala` and `sbt console`?
问题描述
以这些不同的方式运行 scala shell 有什么区别?
What is the difference of running the scala shell in these different ways?
推荐答案
SBT 与 build.sbt
文件定义的特定项目相关联,$ sbt 控制台
code> 将加载与 $ scala
相同的 REPL 环境,但添加了可用于导入的构建中定义的所有项目代码和依赖项.此外,它将使用 build.sbt
定义的 Scala 版本.
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
.
例如:
$ scala
scala> import scalaz._
<console>:7: error: not found: value scalaz
import scalaz._
但是有了这个build.sbt
:
scalaVersion := "2.11.4"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0"
导入成功:
$ sbt console
...
scala> import scalaz._
import scalaz._
该命令加载 Scala 2.11.4 而不是系统范围的 Scala(或 PATH
上的任何版本).
The command loads Scala 2.11.4 instead of the system wide Scala (or any version of it on PATH
).
此外,在构建的 libraryDependencies
中添加新项目后调用 sbt 控制台
将获取它们.
Furthermore, invoking sbt console
after adding new items in the build’s libraryDependencies
will fetch them.
这篇关于运行`scala`和`sbt console`有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!