Index with Examples

Index with Examples

How to...

This page presents an index of the how-to topics with short examples for many of them. Click (details) to jump to the full explanation. See also the Basic Index, which omits the examples and just lists the topics.

Triggered execution (details)

Run a command when sources change (details)

> ~ test

Run multiple commands when sources change (details)

> ~ ;a ;b

Configure the sources that are checked for changes (details)

watchSources <+= baseDirectory { _ / "examples.txt" }

Set the time interval between checks for changes to sources (details)

pollInterval := 1000 // in ms

Inspect the build (details)

Show or search help for a command, task, or setting (details)

> help compile

List available tasks (details)

> tasks

List available settings (details)

> settings

Display forward and reverse dependencies of a setting or task (details)

> inspect compile

Display tree of setting/task dependencies (details)

> inspect compile

Display the description and type of a setting or task (details)

> help compile

Display the delegation chain of a setting or task (details)

> inspect compile

Show the list of projects and builds (details)

> projects

Show the current session (temporary) settings (details)

> session list

Show basic information about sbt and the current build (details)

> about

Show the value of a setting (details)

> show name

Show the result of executing a task (details)

> show update

Show the classpath used for compilation or testing (details)

> show compile:dependency-classpath

Show the main classes detected in a project (details)

> show compile:discovered-main-classes

Show the test classes detected in a project (details)

> show defined-test-names

Interactive mode (details)

Use tab completion (details)

> test-only <TAB>

Show more tab completion suggestions (details)

Press tab multiple times.

Show JLine keybindings (details)

> console-quick
scala> :keybindings

Modify the default JLine keybindings (details)

Configure the prompt string (details)

shellPrompt := { (s: State) => System.getProperty("user.name") + "> " }

Use history (details)

> !

Change the location of the interactive history file (details)

historyPath <<= baseDirectory(t => Some(t / ".history"))

Use the same history for all projects (details)

historyPath <<= (target in LocalRootProject) { t => Some(t / ".history") }

Disable interactive history (details)

historyPath := None

Run commands before entering interactive mode (details)

$ sbt clean compile shell

Running commands (details)

Pass arguments to a command or task in batch mode (details)

$ sbt clean "test-only org.example.Test" "run-main demo.Main a b c"

Provide multiple commands to run consecutively (details)

> ;clean ;compile

Read commands from a file (details)

> < /path/to/file

Define an alias for a command or task (details)

> alias h=help

Quickly evaluate a Scala expression (details)

> eval 2+2

Project metadata (details)

Set the project name (details)

name := "demo"

Set the project version (details)

version := "1.0"

Set the project organization (details)

organization := "org.example"

set the project homepage and other metadata used in a published pom.xml (details)

Generating files (details)

Generate sources (details)

sourceGenerators in Compile <+= <your Task[Seq[File]] here>

Generate resources (details)

resourceGenerators in Compile <+= <your Task[Seq[File]] here>

Configure and use logging (details)

View the logging output of the previously executed command (details)

> last

View the previous logging output of a specific task (details)

> last compile

Show warnings from the previous compilation (details)

> print-warnings

Change the logging level globally (details)

> set every logLevel := Level.Debug

Configure printing of stack traces (details)

> set every traceLevel := 5`

Add a custom logger (details)

Log messages in a task (details)

Configure and use Scala (details)

Set the Scala version used for building the project (details)

version := "1.0"

Disable the automatic dependency on the Scala library (details)

autoScalaLibrary := false

Temporarily switch to a different Scala version (details)

> ++ 2.8.2

Use a local Scala installation for building a project (details)

scalaHome := Some(file("/path/to/scala/home/"))

Build a project against multiple Scala versions (details)

Enter the Scala REPL with a project's dependencies on the classpath, but not the compiled project classes (details)

> console-quick

Enter the Scala REPL with a project's dependencies and compiled code on the classpath (details)

> console

Enter the Scala REPL with plugins and the build definition on the classpath (details)

> console-project

Define the initial commands evaluated when entering the Scala REPL (details)

initialCommands in console := """println("Hi!")"""

Use the Scala REPL from project code (details)

Configure packaging (details)

Use the packaged jar on classpaths instead of class directory (details)

exportJars := true

Add manifest attributes (details)

packageOptions in (Compile, packageBin) +=
   Package.ManifestAttributes( Attributes.Name.SEALED -> "true" )

Change the file name of a package (details)

Modify the contents of the package (details)

mappings in (Compile, packageBin) <+=
   baseDirectory map { dir => ( dir / "example.txt") -> "out/example.txt" }