Linux command
sbt 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Start an interactive sbt shell
sbt
Compile the project
sbt compile
Run the main class
sbt run
Run all tests
sbt test
Run a specific test class
sbt "testOnly [com.example.MySpec]"
Continuously compile
sbt ~compile
Clean and rebuild
sbt clean compile
Package the project
sbt package
说明
sbt (Scala Build Tool) is the standard build tool for Scala projects. It handles compilation, testing, dependency management, packaging, and publishing. sbt uses a build definition written in Scala itself, typically in build.sbt. sbt operates in two modes: batch mode where commands are passed as arguments and sbt exits after execution, and interactive mode where sbt starts a shell for continuous interaction. The interactive shell provides faster feedback since the JVM stays running between commands. Key features include incremental compilation (only recompiling changed files), continuous execution using the ~ prefix (e.g., ~test runs tests on every file save), and cross-building for multiple Scala versions using + prefix.
参数
- -h, --help
- Display help information
- -v, --verbose
- Enable verbose logging
- --debug
- Enable debug logging
- -no-colors
- Disable ANSI color codes in output
- --batch
- Disable interactive mode
- --sbt-version _version_
- Use specified sbt version
- --java-home _path_
- Specify alternate Java installation directory
- -Dkey=val
- Pass system property to the JVM
- -J-Xfoo
- Pass JVM option directly (e.g., -J-Xmx2048M)
- -mem _MB_
- Set memory allocation (e.g., -mem 2048)
FAQ
What is the sbt command used for?
sbt (Scala Build Tool) is the standard build tool for Scala projects. It handles compilation, testing, dependency management, packaging, and publishing. sbt uses a build definition written in Scala itself, typically in build.sbt. sbt operates in two modes: batch mode where commands are passed as arguments and sbt exits after execution, and interactive mode where sbt starts a shell for continuous interaction. The interactive shell provides faster feedback since the JVM stays running between commands. Key features include incremental compilation (only recompiling changed files), continuous execution using the ~ prefix (e.g., ~test runs tests on every file save), and cross-building for multiple Scala versions using + prefix.
How do I run a basic sbt example?
Run `sbt` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -h, --help do in sbt?
Display help information