build.sbt 和 build.scala 有什么区别? [英] What is the difference between build.sbt and build.scala?

查看:34
本文介绍了build.sbt 和 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.sbtbuild.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 文件还可以包含 vals、lazy vals 和 defs(但不是 objects 和 classes).

The .sbt file can also include vals, lazy vals, and defs (but not objects and classes).

请参阅名为.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆