10
votes

I'm having an issue migrating my project to SBT 0.13.

For some reason, the snippet from Generate sources from the SBT documentation doesn't work for me.

Neither a simple .sbt build definition nor a Scala build definition work, unfortunately. Project definition is taken from the documentation:

name := "sbt-test"

sourceGenerators in Compile += Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}

The compiler complains about the type error when compiling the project definition:

~/P/sbt-test ▶ sbt
[info] Loading global plugins from /Users/phearnot/.sbt/0.13/plugins
[info] Loading project definition from /Users/phearnot/Projects/sbt-test/project
/Users/phearnot/Projects/sbt-test/build.sbt:3: error: No implicit for Append.Value[Seq[sbt.Task[Seq[java.io.File]]], sbt.std.FullInstance.M[Seq[java.io.File]]] found,
  so sbt.std.FullInstance.M[Seq[java.io.File]] cannot be appended to Seq[sbt.Task[Seq[java.io.File]]]
sourceGenerators in Compile += Def.task {
                            ^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

UPDATE: Now that AlexIv has pointed out the problem in my SBT file definition, I wonder what is the proper way to move it into a Scala build definition?

3
Re "I wonder what is the proper way to move it into a scala build definition?" - I'm also struggling to achieve this.Phil Harvey

3 Answers

8
votes

Change Def.task in your build.sbt (from gist) to Def.task[Seq[File]] or just leave task[Seq[File]] cause Def is automatically imported into build.sbt:

name := "sbt-test"

sourceGenerators in Compile += task[Seq[File]] {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}

Then call compile in sbt. Test.scala will be generated in ./target/scala-2.10/src_managed/main/demo/Test.scala

0
votes

Use <+= instead of +=:

name := "sbt-test"

sourceGenerators in Compile <+= Def.task {
  val file = (sourceManaged in Compile).value / "demo" / "Test.scala"
  IO.write(file, """object Test extends App { println("Hi") }""")
  Seq(file)
}
0
votes

My sbt version is 0.13.8 and it works for me.