These are chat archives for sbt/sbt

Feb 2016
Feb 27 2016 02:33
hi all - newb question here. I have an sbt task that generates source files into target/.../src_managed/... I want this to be included in a compile step, however i don't want this task to run as part of the compile task.
specifically, this task produces generated scala code from a database schema (which needs to be stable and version controlled, running only very occasionally), but still needs to be included in the compile
the general approach of adding this task to sourceGenerators in Compile seems incorrect here, since this regenerates on each compile apparently.
i'm sure this is a common question, so what's the canonical means of accomplishing this? Thanks in advance.
Tim Harper
Feb 27 2016 05:59
@vovateleport did you figure it out ?
you can define a new task which does the copy, and then inject it as a dependency for the compile task
Nikolay Tatarinov
Feb 27 2016 15:10
What is the meaning of Def.Initialize? Is it some sort of Thing that will be calculated in certain environment(according to def evaluate(map: Settings[Scope]): T) ?
Nikolay Tatarinov
Feb 27 2016 15:47

The reason I'm asking is here.
I have two tasks:

def check(ref: ProjectRef): Task[Boolean]

def getThings(ref: ProjectRef): Def.Initialize[Task[Seq[String]]]

I want to check that ProjectRef meets my requirements with check and retreive info with getThings

First approach.

  def example: Task[Def.Initialize[Task[Seq[String]]]] = {
    val ref: ProjectRef
    check(ref) map { positive =>
      if(positive) getThings(ref) else Def.task(Seq.empty[String])

But the return type is no good.

How about... Lets lift check(ref) from Task[Boolean] to Def.Initialize[Task[Boolean]] and flatMap on it to flatten this to Def.Initialize[Task[Seq[String]]]?
Just like we always do in scala to flatten things: use flatMap

  def example: Task[Def.Initialize[Task[Seq[String]]]] = {
    val ref: ProjectRef
    val liftedCheck: Def.Initialize[Task[Boolean]] = Def.value(check(ref))
    liftedCheck flatMap { positive =>
      if (positive) getThings(ref) else Def.task(Seq.empty[String])

But this doesn't compile.

[error] polymorphic expression cannot be instantiated to expected type;
[error]  found   : [T]sbt.Def.Initialize[sbt.Task[T]]
[error]  required: sbt.Task[sbt.Def.Initialize[sbt.Task[Seq[String]]]]
[error]     liftedCheck flatMap { positive =>
[error]                 ^

Why in a world I should pass Task[T] when doing flatMap on Initialize[Task[T]]?
I also did a lot of tries to make mix of Initialize and Task work together, but without any luck.

Tim Harper
Feb 27 2016 16:51
I'm not on my computer so typing code is difficult. Look at Def.task. Lookup how I am using it in sbt-
Def.task will create a Def.initialize. Also, you don't need to use flatMap, inside of a task definition you can use liftedCheck.value
My plugin has an example of that as eell
Nikolay Tatarinov
Feb 27 2016 17:23
I tried to wrap everything in Def.task, and use value inside, but then I get "Illegal dynamic reference" error during compilation
Feb 27 2016 17:29
you can't name stuff dynamically
Nikolay Tatarinov
Feb 27 2016 17:34
what do you mean exactly?
Sam Halliday
Feb 27 2016 17:39
will sbt ignore files under subdirectories in project?
Sam Halliday
Feb 27 2016 18:02
I want to put a plugin for the presentation compiler under project/pc but I don't want sbt to try and compile it
experiments suggest sbt ignores in
Dale Wijnand
Feb 27 2016 18:54
@fommil yeah it only reads files directly in a directory
Sam Halliday
Feb 27 2016 18:55
eugene yokota
Feb 27 2016 18:58
under project/ is another sbt build
if you define a subproject on project/build.sbt it'll read it. otherwise it won't
turtles all the way down
as per the Initialize[A] discussion above, I wrote a while back, but not sure if would help