一、关于SBT
SBT是一个现代构建工具。它是用Scala编写的,并且针对Scala也提供了很多方便快捷的功能。它也是一个通用的构建工具。
二、为什么使用SBT
- 强大的依赖管理功能
- Ivy用来管理依赖
- 一个只会根据需求更新的模型
- 所有任务的创建都支持Scala
- 可连续执行命令
- 可以在工程的上下文里启动REPL
三、SBT工程目录结构
HelloWorld (base directory)
|__ src (source code directory)
| |__ main
| | |__ scala (main scala sources)
| | |__ resources (files to include in main jar here)
| | |__ java (main java sources)
| |
| |__ test
| |__ scala (test scala sources)
| |__ resources (files to include in test jar here)
| |__ java (test java sources)
|
|__ project
| |__ build.properties (version definition for SBT)
| |__ plugins.sbt (Declaring plugins)
|
|__ build.sbt (sbt build definition files)
|
|__ lib (unmanaged dependencies)
|
|__ target (generated files, like compiled classes, packaged jars, managed files, caches, and documentation)
|
|__ .gitignore (Configuring version control)
四、SBT交互模式
在项目目录下运行sbt命令进行交互模式
sbt
在交互模式中能够运行常见的命令,例如,进行compile
>compile
其它常见命令
command | description |
---|---|
clean | Deletes all generated files (in the target directory). |
compile | Compiles the main sources (in src/main/scala and src/main/java directories). |
test | Compiles and runs all tests. |
console | Starts the Scala interpreter with a classpath including the compiled sources and all dependencies. To return to sbt, type :quit, Ctrl+D (Unix), or Ctrl+Z (Windows). |
run <argument>* | Runs the main class for the project in the same virtual machine as sbt. |
package | Creates a jar file containing the files in src/main/resources and the classes compiled from src/main/scala and src/main/java. |
help <command> | Displays detailed help for the specified command. If no command is provided, displays brief descriptions of all commands. |
reload | Reloads the build definition (build.sbt, project/.scala, project/.sbt files). Needed if you change the build definition. |
具体可参考:
https://www.scala-sbt.org/1.x/docs/Running.html
https://www.scala-sbt.org/1.x/docs/Command-Line-Reference.html