6

One can write something like

(managedClasspath in Compile).value

to obtain the value of managedClasspath in the Compile configuration.

The type of (managedClasspath in Compile) is yet again a sbt.TaskKey (because we call the in method with a ConfigKey).

There is however no value method on SettingKey or TaskKey, and I can't find any implicit class that provides such a method. So how come it exists? Is this some magical macro voodoo?

1 Answer 1

8

It's both, there are a few things at work components:

  1. In sbt, any *XYZKey[_] can be converted into an appropriate Initialize[_] instance via an implicit. This, by default, is an initializer that reads the existing value at the key and returns it.
  2. The sbt.std.MacroValue[T] type is a compile-time only class which holds something that can have .value called on it: http://www.scala-sbt.org/0.13.5/api/index.html#sbt.std.MacroValue. We use this to track the underlying instances in the macro and denote that they have special significance (i.e. we have to rework the code such that we wait for the value to exist before using it).
  3. The sbt.Def object has a set of implicits called macroValueXYZ which lift Initialize[_] instances into the macro API.

So, as you can see, it's a bit of black magic through our internals to get there. We'll have to look into a way to better document the API in a scaladoc tool.

1
  • In item 1, *XYZKey[_] are converted into Initialize[_] without the aid of implicit. *XYZKey[_] inherit from Initialize[_].
    – dkim
    Feb 5, 2018 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.