scala - How to conditionally invoke a task in sbt? -
say taska
heavy task should invoked if it's enabled , taskaenabled
corresponding setting key.
a naive approach be:
val taskaconditional = def.task { (taskaenabled, taska) map { (taskaenabled, taska) => if (taskaenabled) taska.value } }
this won't work due sbt design. taska becomes dependency of taskaconditional, executed regardless of if logic (i.e. taskaenabled ignored).
is there way can achieve want? (i can't change taska it's imported somewhere else)
in sbt 0.13.x can use dynamic computations def.taskdyn:
val taskaconditional = def.taskdyn { if (taskaenabled.value) def.task { taska.value // `.value` macro extract result of taska (execute it) if taskaenabled.value == true } }
Comments
Post a Comment