build.sbt 和 build.scala 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18000103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between build.sbt and build.scala?
提问by MyTitle
I started to learn Scala and almost in every tutorial I see a build.sbtfile which describes project settings. But now I have installed giter8and created a project from template. And generated project from template missed build.sbtfile, but it have build.scala(which seems used for same purposes, but it is more flexible).
我开始学习 Scala,几乎在每个教程中我都会看到一个build.sbt描述项目设置的文件。但是现在我已经giter8从模板安装并创建了一个项目。并从模板丢失的build.sbt文件生成的项目,但它有build.scala(这似乎用于相同的目的,但它更灵活)。
So what is the difference between build.sbtand build.scala?
Which is more preferred and why?
那么build.sbt和之间有什么区别build.scala?
哪个更受欢迎,为什么?
采纳答案by Chris Martin
To give a brief example, this build.sbt:
举一个简单的例子,这个build.sbt:
name := "hello"
version := "1.0"
is a shorthand notation roughly equivalent to this project/Build.scala:
是一个大致相当于这个的速记符号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"
)
}
The .sbtfile can also include vals, lazy vals, and defs (but not objects and classes).
该.sbt文件还可以包含vals、lazy vals 和defs(但不能包含objects 和classes)。
See the SBT document called ".scala build definition", particularly the section "Relating build.sbt to Build.scala".
请参阅名为“.scala 构建定义”的 SBT 文档,特别是“将 build.sbt 与 Build.scala 相关联”部分。
Consider a .scalabuild definition if you're doing something complicated where you want the full expressiveness of Scala.
.scala如果您正在做一些需要 Scala 的完整表现力的复杂事情,请考虑构建定义。
回答by VonC
Update July 2016 (3 years later)
2016 年 7 月更新(3 年后)
Build.scalais officially deprecated in sbt 0.13.12
Build.scala在sbt 0.13.12正式弃用
The
Buildtrait is deprecated in favor of the.sbtformat
该
Build特性是有利于的过时.sbt格式
PR 2530implements that deprecation.
"Appendix: .scalabuild definition" has been updated.
PR 2530实现了该弃用。
“附录:.scala构建定义”已更新。
回答by tkroman
When .sbts are being compiled, they are before that sort of merged with the .scalafiles inside projectdirectory. They can't be used in recursive tasks, that is, you can't customize sbtfrom sbt, for example. For more detailed information, consider reading related section is sbt documentation: http://www.scala-sbt.org/release/docs/Getting-Started/Basic-Def.html#sbt-vs-scala-definition
当.sbts 被编译时,它们在与目录中的.scala文件合并之前project。例如,它们不能用于递归任务,也就是说,您不能sbt从sbt进行自定义。有关更多详细信息,请考虑阅读相关部分是 sbt 文档:http: //www.scala-sbt.org/release/docs/Getting-Started/Basic-Def.html#sbt-vs-scala-definition

