build.sbt 和 build.scala 有什么区别? [英] What is the difference between build.sbt and build.scala?
问题描述
我开始学习 Scala,几乎在每个教程中我都会看到一个描述项目设置的 build.sbt
文件.但是现在我已经安装了 giter8
并从模板创建了一个项目.并且从模板生成的项目缺少 build.sbt
文件,但它有 build.scala
(似乎用于相同的目的,但它更灵活).
I started to learn Scala and almost in every tutorial I see a build.sbt
file which describes project settings. But now I have installed giter8
and created a project from template. And generated project from template missed build.sbt
file, but it have build.scala
(which seems used for same purposes, but it is more flexible).
那么 build.sbt
和 build.scala
有什么区别?
哪个更受欢迎,为什么?
So what is the difference between build.sbt
and build.scala
?
Which is more preferred and why?
推荐答案
举个简单的例子,这个build.sbt
:
To give a brief example, this build.sbt
:
name := "hello"
version := "1.0"
是一个大致相当于这个 project/Build.scala
的速记符号:
is a shorthand notation roughly equivalent to this project/Build.scala
:
import sbt._
import Keys._
object Build extends Build {
lazy val root = Project(id = "root", base = file(".")).settings(
name := "hello",
version := "1.0"
)
}
.sbt
文件还可以包含 val
s、lazy val
s 和 def
s(但不是 object
s 和 class
es).
The .sbt
file can also include val
s, lazy val
s, and def
s (but not object
s and class
es).
请参阅名为.scala 构建定义"的 SBT 文档,特别是该部分将 build.sbt 与 Build.scala 相关联".
See the SBT document called ".scala build definition", particularly the section "Relating build.sbt to Build.scala".
如果您正在做一些需要 Scala 完整表现力的复杂事情,请考虑使用 .scala
构建定义.
Consider a .scala
build definition if you're doing something complicated where you want the full expressiveness of Scala.
这篇关于build.sbt 和 build.scala 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!