26
根據可用的sbt 0.11.0文檔("Common Tasks" wiki page等)以及在Scalaz SBT build和Scalate SBT build中看到了如何完成後,我無法弄清楚爲什麼我的簡單例如不工作:無法使用SBT 0.11從「完整配置」生成源代碼
import sbt._
import Keys._
object MyBuild extends Build {
lazy val project = Project(
id = "root",
base = file("."),
settings = Defaults.defaultSettings ++ Seq(
(sourceGenerators in Compile) <+= (sourceManaged in Compile) map { dir =>
val file = dir/"bla.scala"
IO.write(file, """object Bla extends App { println("bla!") }""")
Seq(file)
}
)
)
}
把該項目/一個空項目的build.scala並運行「SBT編譯」生成/彙編沒有和「SBT運行」抱怨說,它無法找到任何主類。
現在,如果我將設置置於「快速配置」build.sbt中,而不是像上面那樣進行完整配置,它就會起作用。
(sourceGenerators in Compile) <+= (sourceManaged in Compile) map { dir =>
val file = dir/"bla.scala"
IO.write(file, """object Bla extends App { println("bla!") }""")
Seq(file)
}
顯然,需要在「全配置」 - 只項目中創建build.sbt文件是遠遠可取的,至少對我來說。
那麼,爲什麼這個設置不能在完整的配置中工作?
我將上面的內容複製粘貼到project/Build.scala中,運行'sbt run',並打印出bla!如預期。也許檢查文件名是否正確,並且通過在對象中引入println或通過更改設置並驗證它是否生效來加載定義。 –
'project/build.scala'失敗了,其中'project/Build.scala'成功了嗎? – earldouglas
這個傢伙值得大聲迴應,以保持答案不被接受一年。讓我成爲第一個:) –