LinuxCommandLibrary

sbt

Build Scala projects with SBT

TLDR

Start a REPL (interactive shell)

$ sbt
copy

Create a new Scala project from an existing Giter8 template hosted on GitHub
$ sbt new [scala/hello-world.g8]
copy

Compile and run all tests
$ sbt test
copy

Delete all generated files in the target directory
$ sbt clean
copy

Compile the main sources in src/main/scala and src/main/java directories
$ sbt compile
copy

Use the specified version of sbt
$ sbt -sbt-version [version]
copy

Use a specific jar file as the sbt launcher
$ sbt -sbt-jar [path]
copy

List all sbt options
$ sbt -h
copy

SYNOPSIS

sbt [options] [command [command-options]]

PARAMETERS

-h, --help
    Displays a help message and exits.

-mem <size>
    Sets the maximum JVM heap size for sbt (e.g., -mem 2048 for 2GB).

-debug, -trace
    Enables verbose debugging or stack tracing output.

-sbt-version <version>
    Specifies a particular sbt version to use for the project.

-sbt-dir <directory>
    Specifies the directory where sbt stores its global files and caches.

-no-share
    Disables sharing of project configuration and caches among projects.

-batch
    Runs sbt in non-interactive batch mode. Useful for scripting.

-no-colors
    Disables ANSI color output in the console.

-warn-fatal-warnings
    Treats all warnings as fatal errors, stopping the build.

-Dsbt.=
    Passes a system property to the JVM running sbt (e.g., -Dsbt.log.format=false).

--
    Separator indicating that subsequent arguments are commands or arguments to be passed to sbt itself, not launcher options.

DESCRIPTION

sbt (Simple Build Tool) is an open-source build tool primarily designed for Scala projects, offering robust support for Java as well. It provides features like fast incremental compilation, automated dependency management via Apache Ivy, and a powerful interactive shell. Developers use sbt to compile, test, run, and package their applications efficiently. Its configuration is handled through Scala-based build definition files (typically build.sbt), which allows for highly flexible and programmatic build logic. sbt aims to optimize the development workflow for JVM-based projects, especially those leveraging Scala's advanced language features.

CAVEATS

Initial startup of sbt can be notably slow due to JVM spin-up and dependency resolution. It can also be memory-intensive, especially for large projects, requiring sufficient JVM heap allocation. The Scala-centric configuration (build.sbt) can present a learning curve for developers unfamiliar with Scala DSLs. Version compatibility between sbt, Scala, and plugins sometimes requires careful management.

INTERACTIVE MODE

When invoked without specific commands, sbt enters an interactive shell. This mode provides a powerful REPL-like environment where developers can execute build commands, inspect settings, and get immediate feedback, significantly accelerating the development cycle.

BUILD DEFINITION (BUILD.SBT)

Project configuration in sbt is primarily done through build.sbt files. These files are themselves Scala programs, allowing for highly expressive and programmatic control over the build process, including task definitions, dependency management, and project settings.

PLUGINS

sbt features a rich and extensible plugin ecosystem. Plugins extend sbt's core functionality, enabling integrations with various tools, facilitating common tasks like publishing artifacts, code generation, and deployment, and enhancing the overall build experience.

HISTORY

sbt was originally created by Mark Harrah and first released around 2008. It rapidly became the de-facto standard build tool for Scala projects due to its strong integration with Scala's features, particularly incremental compilation. Early versions (0.7.x) used an XML-based configuration, but later releases (0.10+ onwards) transitioned to a more powerful and flexible Scala-based DSL (Domain Specific Language) for build definitions (build.sbt). This evolution cemented sbt's role as a sophisticated and efficient build tool for the Scala ecosystem.

SEE ALSO

java(1), javac(1), mvn(1), gradle(1), scala(1)

Copied to clipboard