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?
Run “sbt hello” from command line to invoke the task. Run “sbt tasks” to see this task listed. To declare a new task, define a lazy val of type TaskKey : lazy val sampleTask = taskKey[Int] ("A sample task.") The name of the val is used when referring to the task in Scala code and at the command line.
Append Only (‘a’): Open the file for writing. The file is created if it does not exist. The handle is positioned at the end of the file. The data being written will be inserted at the end, after the existing data. Append and Read (‘a+’): Open the file for reading and writing. The file is created if it does not exist.
For example, if we pass id in the above method then it will find and return all elements whose id is a match. If no web element is found with the provided mechanism then it never throws NoSuchElementException instead it returns a List with size zero. This method is affected by implicit wait which is set for a WebDriver session.
The data being written will be inserted at the end, after the existing data. When the file is opened in append mode, the handle is positioned at the end of the file. The data being written will be inserted at the end, after the existing data.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With