什么是 Scala 的简单构建工具 (sbt),为什么使用它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24586605/
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 Scala's Simple Build Tool (sbt) and why is it used?
提问by swaheed
I am new in Scala and I have to learn Scala and SBT, I read the sbt tutorial but i am unable to understand the use of sbt, for what purpose its been used.After reading this tutorialI am still confused can any one will explain it in simple words, also suggest me if there is some tutorial for simple build tool
我是 Scala 新手,我必须学习 Scala 和 SBT,我阅读了 sbt 教程,但我无法理解 sbt 的使用,它的用途是什么。阅读本教程后,我仍然很困惑,谁能解释一下用简单的话来说,如果有一些简单的构建工具的教程,也建议我
回答by Jesper
When you write small programs that consist of only one, or just two or three source files, then it's easy enough to compile those source files by typing scalac MyProgram.scalain the command line.
当您编写仅包含一个或两个或三个源文件的小程序时,通过scalac MyProgram.scala在命令行中键入内容来编译这些源文件是很容易的。
But when you start working on a bigger project with dozens or maybe even hundreds of source files, then it becomes too tedious to compile all those source files manually. You will then want to use a build tool to manage compiling all those source files.
但是,当您开始处理包含数十个甚至数百个源文件的更大项目时,手动编译所有这些源文件就变得太乏味了。然后,您将需要使用构建工具来管理编译所有这些源文件。
sbt is such a tool. There are other tools too, some other well-known build tools that come from the Java world are Antand Maven.
sbt 就是这样一个工具。还有其他工具,来自 Java 世界的其他一些著名的构建工具是Ant和Maven。
How it works is that you create a project file that describes what your project looks like; when you use sbt, this file will be called build.sbt. That file lists all the source files your project consists of, along with other information about your project. Sbt will read the file and then it knows what to do to compile the complete project.
它的工作原理是您创建一个项目文件来描述您的项目的样子;当你使用 sbt 时,这个文件将被称为build.sbt. 该文件列出了项目包含的所有源文件,以及有关项目的其他信息。Sbt 将读取文件,然后它知道如何编译完整的项目。
Besides managing your project, some build tools, including sbt, can automatically manage dependencies for you. This means that if you need to use some libraries written by others, sbt can automatically download the right versions of those libraries and include them in your project for you.
除了管理你的项目,一些构建工具,包括 sbt,可以自动为你管理依赖项。这意味着如果您需要使用其他人编写的某些库,sbt 可以自动下载这些库的正确版本并将它们包含在您的项目中。

