These are chat archives for sbt/sbt

27th
Feb 2016
virusdave
@virusdave
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
@timcharper
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
@rockjam
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
@rockjam
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
Okay:

  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
@timcharper
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-
sbt-jnaerator
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
Well
Nikolay Tatarinov
@rockjam
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
Perry
@pfn
Feb 27 2016 17:29
you can't name stuff dynamically
Nikolay Tatarinov
@rockjam
Feb 27 2016 17:34
what do you mean exactly?
Sam Halliday
@fommil
Feb 27 2016 17:39
will sbt ignore files under subdirectories in project?
Sam Halliday
@fommil
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
@dwijnand
Feb 27 2016 18:54
@fommil yeah it only reads files directly in a directory
Sam Halliday
@fommil
Feb 27 2016 18:55
cool
eugene yokota
@eed3si9n
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 http://eed3si9n.com/4th-dimension-with-sbt-013 a while back, but not sure if would help