【问题标题】:Copying resources using SBT使用 SBT 复制资源
【发布时间】:2015-11-02 19:26:08
【问题描述】:

我有一个使用 SBT 的 Scala 项目。我的项目中有一个目录html,当使用sbt run 运行项目或使用sbt-assembly 将其打包到Jar 中时,需要复制该目录。无论哪种方式,我都希望将html 目录复制到target/scala-2.11/classes/html

我试过了:

resourceDirectory in Compile := file("html")

...将html 中的每个文件移动到target/scala-2.11/classes,而没有中间html 目录。

和:

unmanagedResources in Compile := Seq(file("html"))

...复制目录,但其中没有文件!

【问题讨论】:

  • 你为什么不把html放到其他目录然后添加到unmanagedResourceDirectories呢?
  • 我可以,但我不希望仅仅因为 SBT 的限制而拥有更复杂的目录结构

标签: scala jar sbt sbt-assembly


【解决方案1】:

也许不是很好,但工作:

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
}

【讨论】:

    【解决方案2】:

    如果你在sbt compile之后运行sbt copy-resources 你可能有一些运气。最近碰到这个。

    您的 html 文件夹必须位于 scr/main/resources 或您的资源目录在构建中设置的任何位置......

    【讨论】:

      猜你喜欢
      • 2013-11-10
      • 2013-04-18
      • 2012-11-06
      • 1970-01-01
      • 2011-10-01
      • 2018-08-24
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多