基于可用的sbt 0.11.0文档("常见任务"维基页面和其他),在看到如何在Scalaz SBT构建和Scalate SBT构建中完成后,我无法弄清楚为什么我的简单示例不起作用:
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)
}
)
)
}
Run Code Online (Sandbox Code Playgroud)
把它放在一个空项目的project/build.scala上并运行"sbt compile"生成/编译什么都没有,"sbt run"抱怨它找不到任何主类.
现在,如果我将设置放在"快速配置"build.sbt中,而不是如上所述的完整配置,它就可以正常工作.
(sourceGenerators in Compile) <+= (sourceManaged in Compile) map { dir => …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个简单的辅助方法,它接收可以关闭的东西和一些接收前者的函数,并确保在执行函数后关闭"closeable".
例如,我想像这样使用它:
closing(new FileOutputStream("/asda"))(_.write("asas"))
Run Code Online (Sandbox Code Playgroud)
我的意思是
object Helpers {
def closing[T <: { def close }](closeable: T)(action: T => Unit): Unit =
try action apply closeable finally closeable close
}
Run Code Online (Sandbox Code Playgroud)
但是在尝试编译这个简单的测试时:
object Test {
import Helpers._
closing(new FileOutputStream("/asda"))(_.write("asas"))
}
Run Code Online (Sandbox Code Playgroud)
编译器抱怨:
推断类型参数[java.io.FileOutputStream]不符合方法结束的类型参数bounds [T <:AnyRef {def close:Unit}]
有什么想法吗?