The documentation for sbt seems to be really lacking here, so I'd like to get a definitive answer on this: what is the difference between "+=", "++=", "<+=", "<++=", and "<<=" when operating on Keys?
-
Would you mind backing up the claim *"The documentation for sbt seems to be really lacking here"*? What about http://www.scala-sbt.org/release/docs/Getting-Started/More-About-Settings.html? – Jacek Laskowski May 15 '14 at 22:41
-
1I've read all the documentation on the sbt website, and I have also purchased and read the MEAP version of "SBT In Action". Common operators such as := and += and ++= are well defined, but others such as <+= and <<= are not. So if you are doing something above and beyond a basic build, there's not much guidance. – Jeff May 15 '14 at 23:43
3 Answers
You cannot find documentation, because as @JacekLaskowski correctly pointed out all operators except for +=
, ++=
and :=
are deprecated.
You can however find the Documentation if you switch to older version of sbt.
If you however are stuck to older version, this is their meaning (via documentation):
+=
and++=
append to previous value, where first appends single element and next appends aSeq
~=
transforms value, e.g. you want to use value stored in a setting to get a new setting.<<=
depends on another key, for example if you callorganization <<= name
, thenorganization
value is equal toname
value. You can depend on multiple values, e.g.organization <<= (name, version) { (n, v) => /* do something with values */ }
<+=
and<++=
are appending with dependencies, like the append, but you can use another's setting value to compute new value
Said that, @JacekLaskowski is right, and if you are using sbt 13.x or greater you should not have to use those operators in favours of macros.

- 72,696
- 27
- 242
- 420

- 13,659
- 1
- 35
- 47
-
2This was what I was looking for, thank you. The reason why I needed to know is that documentation for other plugins for sbt still use the "deprecated" operators (for example, sbt-native-packager). Since I am new to sbt and have only used 0.13+, I was never given exposure to the older syntax. This is very helpful. – Jeff May 16 '14 at 18:38
-
These [release notes for migrating from 0.12.x](http://www.scala-sbt.org/0.13/docs/Migrating-from-sbt-012x.html) were very helpful to me in understanding how to move away from the deprecated operators. – rbellamy Nov 28 '16 at 23:24
Quoting Task v. Setting keys:
A
TaskKey[T]
is said to define a task.sbt's map describing the project can keep around a fixed string value for a setting such as
name
, but it has to keep around some executable code for a task such ascompile
-- even if that executable code eventually returns a string, it has to be re-run every time.A given key always refers to either a task or a plain setting. That is, "taskiness" (whether to re-run each time) is a property of the key, not the value.
In other words, settings are immutable and initialized at build startup (similar to val
s in Scala) while tasks are executed every time they're called (similar to def
s in Scala).
Quoting Defining tasks and settings:
Using
:=
, you can assign a value to a setting and a computation to a task. For a setting, the value will be computed once at project load time. For a task, the computation will be re-run each time the task is executed.
Quoting Appending to previous values: += and ++=:
Assignment with
:=
is the simplest transformation, but keys have other methods as well. If theT
inSettingKey[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.
Wrapping it up, you should only be concerned with :=
(assignment macro), +=
(append macro) and ++=
(concatenation macro). The remaining ones, i.e. <<=
, <+=
and <++=
, are no longer recommended for common use cases.
As a matter of fact, all operations can be expressed with the simple assignment macro :=
(paraphrasing the upcoming book SBT in Action).
Are you really sure, the docs are "really lacking here"?! I doubt.

- 72,696
- 27
- 242
- 420
-
1<<=, <+=, and <++= are exactly the operators I'm concerned with. Basic scenarios that only require := and += and ++= are well documented, but more advanced builds that require deeper configuration are not. Can you point me towards any sort of documentation where those advanced operators and their use cases are described? In addition, where is it stated that, "The remaining ones, i.e. <<=, <+= and <++=, are no longer recommended for common use cases" as you claim? – Jeff May 15 '14 at 23:52
-
I agree that it's difficult to locate specific information in the sbt docs, although the docs have been greatly improved over time. Could it be that sbt is so simple and abstract that it is ineffable? In a word, undocumentable? – som-snytt May 16 '14 at 02:12
-
The loose quotation is from the book "sbt in Action" and after a while working with sbt I very rarely faced a need for the other operators (mainly when I needed to show off my understanding of sbt :)) – Jacek Laskowski May 16 '14 at 12:48
-
1sbt-web uses the deprecated operators everywhere. So, to understand what it does and how to use it, one needs to know what that operators mean. And the sbt API documentation has zero comments. Even the non deprecated ones. That's is very frustrating and mitigates my hope to convince my boss to use scala and sbt in our new projects. – Readren Apr 26 '16 at 05:17
-
2In fact, even the examples of the "SBT in Action" book make use of the deprecated operators. Look [here](https://github.com/jsuereth/sbt-in-action-examples/blob/master/chapter3/build.sbt). The line `resourceGenerators in Compile <+= makeVersionProperties` for example. – Readren Apr 26 '16 at 21:02
-
1When the operators were deprecated, is there any documentation or porting guide what they mean or how to translate them to a currently used syntax? – Suma May 24 '16 at 09:21
When the operators were deprecated, is there any documentation or porting guide what they mean or how to translate them to a currently used syntax?
You can see example of such translation in recent (Dec. 2016) commits (in scala/scala itself) like:
You will see:
- incOptions <<= (incOptions in LocalProject("root")),
+ incOptions := (incOptions in LocalProject("root")).value,
or
- packagedArtifact in (Compile, packageBin) <<= (artifact in (Compile, packageBin), bundle).identityMap,
+ packagedArtifact in (Compile, packageBin) := (((artifact in (Compile, packageBin)).value, bundle.value)),
You can see more about the deprecation of those operators in sbt PR 2711, sbt PR 2716 and sbt/notes/0.13.13/ops_deprecation.md
.

- 1,262,500
- 529
- 4,410
- 5,250