Done in SBT 0.13.x

I am using SBT 0.13.2 and I want to run my task by completing a compilation task. I know that I can achieve this using the triggeredBy method, as in taskDefinition.triggeredBy(compile in Compile) .

I have build.sbt with my custom task.

The problem is that I cannot understand why the following works as expected

 val triggeredTask = taskKey[Unit]("Triggered by compile") triggeredTask <<= Def.task { println("TRIGGERED BY COMPILE") }.triggeredBy(compile in Compile) 

but the next one does not work ( compile runs just fine, but my task does not start)

 val triggeredTask = taskKey[Unit]("Triggered by compile") triggeredTask := Def.task { println("TRIGGERED BY COMPILE") }.triggeredBy(compile in Compile).value 

My understanding was that SBT 0.13 made <<= deprecated and := should be enough.

+6
source share
1 answer

I might misunderstand what you are trying to do.

If I make your example more detailed, it will look like this:

 val triggeredTaskKey = taskKey[Unit]("Triggered by compile") val anonymousTask = Def.task { println("TRIGGERED BY COMPILE") }.triggeredBy(compile in Compile) // I imagine the macro doing something like this triggeredTaskKey <<= anonymousTask map (identity) 

It also does not call an anonymous compile task.

Note that <<= is a nice version of set that retrieves location information. And set is just an alias for Def.setting(key, value, position) , which in turn creates a new Setting instance. Note that the installation instance that is created internally has a constructor of these three parameters.

I do not think that there is a way in sbt to declare a parameter without a key (maybe I'm wrong here). However, it seems that you want to create a setting (which starts) without a key.

This may be caused by an error, I'm not sure that sbt should recursively track dependencies to search for tasks with the triggeredBy key in info . This is currently not the case (as shown in the trigger method.

Theoretically, you can do work around that creates settings with the right triggers associated with any arbitrary key. I'm not sure how this will work.

+1
source

All Articles