我有一个使用SBT的Scala项目。我的项目中有一个目录html,当项目使用sbt run运行时,或者当我使用sbt-assembly将其打包到Jar中时,需要复制该目录。无论采用哪种方法,我都希望将html目录复制到target/scala-2.11/classes/html。
我试过了:
resourceDirectory in Compile := file("html")...which将html中的每个文件移动到target/scala-2.11/classes,而不是中间的html目录。
和:
unmanagedResources in Compile := Seq(file("html"))...which复制目录,但不复制其中的任何文件!
发布于 2015-08-13 06:45:44
也许不是很好,但很有效:
val html = "html"
lazy val compileCopyTask = taskKey[Unit](s"Copy $html.")
compileCopyTask := {
println(s"Start copying $html")
val mainVersion = scalaVersion.value.split("""\.""").take(2).mkString(".")
val to = target.value / ("scala-" + mainVersion) / html / "classes"
to.mkdirs()
val from = baseDirectory.value / html
IO.copyDirectory(from,to)
println(s"$from -> $to...done.")
}
compile in Compile := {
compileCopyTask.value
(compile in Compile).value
}发布于 2017-07-11 02:39:55
如果你在sbt compile之后运行sbt copy-resources,你可能会有一些运气。最近遇到了这个问题。
您的html文件夹必须位于scr/ resourceDirectory /resources或在构建中设置的任何位置...
https://stackoverflow.com/questions/31927051
复制相似问题