开发者

Creating SBT task to copy directories during compile?

开发者 https://www.devze.com 2023-04-12 15:19 出处:网络
I\'m new to the whole SBT and Scala scene and am trying to build a project that uses Java/Scala classes and Hibernate.I\'开发者_运维知识库m getting the project to build fine -- I just have to manually

I'm new to the whole SBT and Scala scene and am trying to build a project that uses Java/Scala classes and Hibernate. I'开发者_运维知识库m getting the project to build fine -- I just have to manually copy over my hibernate config files to my target/scala<version>/classes folder so they can be picked up by hibernate.

Is there a way to create a task in SBT to copy these folders over on each compile? This is my Build.scala file:

import sbt._

object Sportsbook extends Build {
  lazy val project = Project (
    "sportsbook",
    file("."),
    copyConfigTask
  )

  val copyConfig = TaskKey[Unit]("copy", "Copy hibernate files over to target directory")

  /*
  // Something like this
  lazy val copyConfigTask = copyConfig <<=
    val configDir1 = baseDirectory / "config"
    val configDir2 = outputPath / "config"
    IO.copyDirectory(configDir1, configDir2)
  */
}


The most direct means to achieve this is to move the files into ./src/main/resources/config.

Alternatively, add ${base}/config to resourceDirectories in Compile.

resourceDirectories in Compile <+= baseDirectory / "config"

Unfortunately, files in there will be copied to the root of the classpath. You would need to move them to ./src/config/config to restore that. (See how the mappings for resources are based on the relative location of resource files to the base resource directories)

Do you want the files packaged in your JAR? Both of these answers would result in that. You could take them out of mappings in packageBin to avoid this.

mappings in (Compile, packageBin) ~= (_.filter { case (file, outpath) => outpath.startsWith("/config")} )
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号