synapse
synapse

Reputation: 5728

How exactly sbt figures out task names?

Suppose there's something like this in build.sbt

val printMessage = taskKey[Unit]("Simple task")

printMessage := {
    println("Hello")
}

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

Upvotes: 4

Views: 86

Answers (1)

Chris
Chris

Reputation: 2895

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

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

So when you call taskKey[Unit]("SimpleTask"), that's expanded to a macro that finds the val printMessage and uses that to infer the task key's name.

Upvotes: 4

Related Questions