How can this value be called on SetKey or TaskKey?

You can write something like

(managedClasspath in Compile).value 

to get the managedClasspath value in the Compile configuration.

The type (managedClasspath in Compile) again sbt.TaskKey (because we are calling the in method with ConfigKey ).

However, there is no value method on SettingKey or TaskKey , and I cannot find any implicit class that provides such a method. So how does it exist? Is this some kind of magical voodoo macro?

+5
source share
1 answer

In both cases, there are several components:

  • In sbt, any *XYZKey[_] can be converted to the corresponding Initialize[_] instance via implicit. By default, this is an initializer that reads the existing value in the key and returns it.
  • The sbt.std.MacroValue[T] is just a compile-time class that contains something that may have a .value called on it: http://www.scala-sbt.org/0.13.5/api/ index.html # sbt.std.MacroValue . We use this to track key instances in a macro and indicate that they have a special meaning (i.e., we must redesign the code so that we expect the value to exist before it is used).
  • The sbt.Def object has a set of implications called macroValueXYZ that raise Initialize[_] instances in the macro API.

So, as you can see, this is a bit of black magic through our inner forces to get there. We will need to learn how to better document the API in the scaladoc tool.

+7
source

Source: https://habr.com/ru/post/1200035/


All Articles