定义一个taskKey,比如说
你的行动任务
然后
yourActionTask <<= (baseDirectory, target, packageBin in Compile, resources in Compile...) map { (basedir, targetDir, bin, res...)=>
// use these resources to complete your task as per your needs
}
顺便提一句。您可以在 Keys.scala 源代码或 sbt 的 scaladoc 中找到更多预定义的任务/键。
这是一个您可以参考的示例,它是从我的一个构建文件中提取的(只需将 TaskKey 和 Task 定义结合在一起,因为我不打扰我将来会重用 TaskKey):
val distTask = TaskKey[Unit]("dist", "distribute the deployment package of eromanga") <<= (baseDirectory, target, fullClasspath in Compile, packageBin in Compile, resources in Compile, streams) map {
(baseDir, targetDir, cp, jar, res, s) =>
s.log.info("[dist] prepare distribution folders...")
val assemblyDir = targetDir / "dist"
val confDir = assemblyDir / "conf"
val libDir = assemblyDir / "lib"
val binDir = assemblyDir / "bin"
Array(assemblyDir, confDir, libDir, binDir).foreach(IO.createDirectory)
s.log.info("[dist] copy jar artifact to lib...")
IO.copyFile(jar, libDir / jar.name)
s.log.info("[dist] copy 3rd party dependencies to lib...")
cp.files.foreach(f => if (f.isFile) IO.copyFile(f, libDir / f.name))
s.log.info("[dist] copy shell scripts to bin...")
((baseDir / "bin") ** "*.sh").get.foreach(f => IO.copyFile(f, binDir / f.name))
s.log.info("[dist] copy configuration templates to conf...")
((baseDir / "conf") * "*.xml").get.foreach(f => IO.copyFile(f, confDir / f.name))
s.log.info("[dist] copy examples chanenl deployment...")
IO.copyDirectory(baseDir / "examples", assemblyDir / "examples")
res.filter(_.name.startsWith("logback")).foreach(f => IO.copyFile(f, assemblyDir / f.name))
}