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] [commands]

PARAMETERS

help
    Displays help information for sbt and its commands.

sbt-version
    Specifies the sbt version to use for the build.

batch
    Run sbt in batch mode (non-interactive).

error
    Log errors only.

warn
    Log warnings and errors.

info
    Log informational messages, warnings, and errors (default).

debug
    Log debug messages, informational messages, warnings, and errors.

trace
    Log everything.


    Executes the specified sbt command. Common commands include 'compile', 'test', 'run', 'package', 'publish'.


    Executes the specified sbt command with specific arguments passed to it.

DESCRIPTION

sbt is an open-source build tool designed for Scala and Java projects. It is similar to tools like Maven and Gradle, but specifically tailored to the Scala ecosystem.

sbt manages dependencies, compiles code, runs tests, packages applications, and publishes artifacts to repositories. It uses a declarative build definition written in Scala, which provides powerful configuration capabilities. sbt's interactive mode allows for fast iteration during development.

Its key features include: dependency management (using Ivy under the hood), incremental compilation (to speed up build times), plugins (to extend functionality), support for multiple projects in a single build, and integration with popular IDEs. sbt's flexibility makes it suitable for projects of all sizes, from simple scripts to complex multi-module applications.

CAVEATS

sbt's configuration syntax can be initially complex for users unfamiliar with Scala. Understanding the build definition in `build.sbt` is crucial for managing projects effectively. Performance can sometimes be an issue with very large projects.

BUILD DEFINITION

sbt projects are configured using a `build.sbt` file, written in Scala. This file defines the project's settings, dependencies, and tasks. Key settings include `name`, `version`, `scalaVersion`, and `libraryDependencies`. Tasks define actions to be performed, such as compiling code or running tests.

INTERACTIVE MODE

Running `sbt` without any commands starts the interactive mode. In this mode, you can enter commands directly, and sbt will execute them. This is useful for rapid development and experimentation.

PLUGINS

sbt's functionality can be extended using plugins. Plugins can add new commands, modify existing tasks, or integrate with other tools and frameworks. Plugins are typically added by declaring them as dependencies in the `plugins.sbt` file.

HISTORY

sbt was created by Mark Harrah and is currently maintained by a dedicated team of developers. It emerged as a response to the challenges of building Scala projects with existing Java build tools. sbt has evolved significantly over the years, adding features like incremental compilation, plugin support, and improved dependency management. It is now the standard build tool for the Scala ecosystem and is also widely used for Java projects.

SEE ALSO

maven(1), gradle(1)

Copied to clipboard