我在将项目迁移到SBT 0.13
时遇到问题。
出于某种原因,来自SBT文档的Generate sources的片段对我不起作用。
遗憾的是,简单的.sbt
构建定义和Scala构建定义都不起作用。项目定义取自文档:
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)
}
编译器在编译项目定义时会抱怨类型错误:
~/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?
更新:现在AlexIv已经指出了我的SBT文件定义中的问题,我想知道将它移动到Scala构建定义的正确方法是什么?
答案 0 :(得分:8)
将build.sbt中的Def.task
(从gist)更改为Def.task[Seq[File]]
,或者只是离开task[Seq[File]]
因为Def
会自动导入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)
}
然后在sbt中调用compile
。 Test.scala
将生成./target/scala-2.10/src_managed/main/demo/Test.scala
答案 1 :(得分:0)
使用<+=
代替+=
:
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)
}
答案 2 :(得分:0)
我的sbt版本是0.13.8,它适用于我。