Search code examples
scalasbtsbt-native-packager

Use cases for different sbt Key operators


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?


Solution

  • 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 a Seq
    • ~= 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 call organization <<= name, then organization value is equal to name 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.