How exactly does sbt determine task names?

Suppose something like this in build.sbt

 val printMessage = taskKey[Unit]("Simple task") printMessage := { println("Hello") } 

How does sbt find out that this task is called printMessage and makes it available in the CLI when there is no line with this text? I would understand if the code was something like val printMessage = taskKey[Unit]("printMessage", "description") , but it really puzzles me

+4
source share
1 answer

SBT has macro , sbt.std.KeyMacro.taskKeyImpl , which takes a String description and sbt.std.KeyMacro.taskKeyImpl task name from the sbt.std.KeyMacro.taskKeyImpl name val.

This macro is aliased to taskKey[T] in the sbt package object.

Therefore, when you call taskKey[Unit]("SimpleTask") , which expands to a macro that finds val printMessage , and uses this to print the name of the task key.

+4
source

All Articles