我想出了这个解决方案,它定义了依赖于以前的编译任务新的编译任务(从而有效地让我的右钩源编译后,它的包装前)
def mySettings = {
// add functionality to the standard compile task
inConfig(Compile)(Seq(compile in Compile <<= (target,streams,compile in Compile) map{
(targetDirectory, taskStream, analysis) =>
import taskStream.log
// this runs after compile but before package-bin
recursiveListFiles(targetDirectory, ".*javax.*".r) foreach {
file =>
log.warn("deleting matched resource: " + file.getAbsolutePath())
IO.delete(file)
}
analysis
})) ++
Seq(name := "MyProject", version := "1.0", exportJars := true)
}
def recursiveListFiles(f: File, r: Regex): Array[File] = {
val these = f.listFiles
val good = these.filter(f => r.findFirstIn(f.getName).isDefined)
good ++ these.filter(_.isDirectory).flatMap(recursiveListFiles(_, r))
}
它比我希望的复杂一点,但它允许我在打包之前进行各种修改(在这种情况下,搜索目标文件夹删除与正则表达式匹配的所有类文件)。此外,它还实现了坚持默认SBT生命周期的第二个目标。
这是一个比我自己的更好的解决方案,也是一个很好的答案,因为它还设法澄清了一些核心SBT概念。 –
请注意,〜=没有记录在0.13页面上,解释存在于0.12文档中http://www.scala-sbt.org/0.12.4/docs/Getting-Started/More-About-Settings.html –
语法为0.13 (编译,packageBin):= { (映射到(Compile,packageBin))。value.filter {case(file,toPath)=> toPath!=“javax/servlet/Servlet.class “ } }''' –