Appending values

Appending to previous values: += and ++=

Assignment with := is the simplest transformation, but keys have other
methods as well. If the T in SettingKey[T] is a sequence, i.e. the key’s
value type is a sequence, you can append to the sequence rather than
replacing it.

+= will append a single element to the sequence.

++= will concatenate another sequence.

For example, the key sourceDirectories in Compile has a Seq[File] as its
value. By default this key’s value would include src/main/scala. If you
wanted to also compile source code in a directory called source (since
you just have to be nonstandard), you could add that directory:

When settings are undefined

Whenever a setting uses :=, +=, or ++= to create a dependency on itself
or another key’s value, the value it depends on must exist. If it does
not, sbt will complain. It might say “Reference to undefined setting“,
for example. When this happens, be sure you’re using the key in the
scope that defines it.

It’s possible to create cycles, which is an error; sbt will tell you if
you do this.

Tasks based on other keys’ values

You can compute values of some tasks or settings to define or append a value for another task. It’s done by using Def.task and taskValue as an argument to :=, +=, or ++=.

As a first example, consider appending a source generator using the project base directory and compilation classpath.