combining input task with dynamic task in sbt

sbt, scala

Solution

Trial and error method gave me the answer but non a single bit of understanding. Here it is:

import sbt._
import Keys._
import Def.Initialize
import complete.DefaultParsers._

object TestBuild extends Build {
  val sampleInput = inputKey[Seq[String]]("sample dynamic input task")
  val sampleDynamic = taskKey[Seq[String]]("sample dynamic task")

  override lazy val settings = super.settings ++ Seq(
    sampleDynamic := Def.taskDyn {
      val sources = Seq("ab", "csd", "efda")
      sources.map(sampleTaskFor _).joinWith(_.join)
    }.value,
    sampleInput := Def.inputTaskDyn {
      val sources = spaceDelimited("<arg>").parsed
      sampleTaskAll(sources)
    }.evaluated
  )

  private def sampleTaskFor(source : String) : Initialize[Task[String]] = Def.task {
    source + " : " + source
  }

  private def sampleTaskAll(sources : Seq[String]) : Initialize[Task[Seq[String]]] = Def.taskDyn {
    sources.map(sampleTaskFor _).joinWith(_.join)
  }
}

For a reason I can not comprehend you should isolate creating multitask out of sequence of single tasks in a separate method.

Problem

I'd like to make an input task that proceed user input and generate bunch of subtasks to run. Here is the example: ``` import sbt._ import Keys._ import Def.Initialize import complete.DefaultParsers._ object TestBuild extends Build { val sampleInput = inputKey[Seq[String]]("sample dynamic input task") val sampleDynamic = taskKey[Seq[String]]("sample dynamic task") override lazy val settings = super.settings ++ Seq( sampleDynamic := Def.taskDyn { val sources = Seq("ab", "csd", "efda") sources.map(sampleTaskFor _).joinWith(_.join) }.value, sampleInput := Def.inputTaskDyn { val sources = spaceDelimited("<arg>").parsed sources.map(sampleTaskFor _).joinWith(_.join) }.value ) private def sampleTaskFor(source : String) : Initialize[Task[String]] = Def.task { source + " : " + source } } ``` There are two samples. The first works and shows simple taskDyn with predefined input. The second is intended dynamic task with user input that refuses to compile with error that I can not interpret ``` [error] home/project/build.scala:15: Illegal dynamic reference: Def [error] sampleInput := Def.inputTaskDyn { [error] ^ [error] one error found [error] (compile:compile) Compilation failed ``` How can I avoid it? Trial and error log There I would append my question with different proposed changes that still can not solve the issue replace InputTask.value with InputTask.evaluated ``` sources.map(sampleTaskFor _).joinWith(_.join) - }.value + }.evaluated ) ``` If I would able to define correct InputTask it should be accessed via `evaluated` method, as I've found both in documentation and in practice after trying to play with different InputTasks that compiles. Still that would not fix the issue that sbt macro engine refuses provided `inputTaskDyn`. waiting for other suggestions

Original source