创建 SBT 任务以在编译期间复制目录?
我对整个 SBT 和 Scala 场景很陌生,正在尝试构建一个使用 Java/Scala 类和 Hibernate 的项目。我正在让项目构建得很好——我只需手动将我的 hibernate 配置文件复制到我的 target/scala
文件夹,以便 hibernate 可以拾取它们。
有没有办法在 SBT 中创建一个任务来在每次编译时复制这些文件夹?这是我的 Build.scala 文件:
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)
*/
}
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)
*/
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现此目的最直接的方法是将文件移动到
./src/main/resources/config
中。或者,将
${base}/config
添加到Compile 中的resourceDirectories
。不幸的是,其中的文件将被复制到类路径的根目录。您需要将它们移至
./src/config/config
才能恢复。 (查看资源的映射
如何基于资源文件与基本资源目录的相对位置)您希望将文件打包到 JAR 中吗?这两个答案都会导致这个结果。您可以将它们从 packageBin 中的映射中取出来避免这种情况。
The most direct means to achieve this is to move the files into
./src/main/resources/config
.Alternatively, add
${base}/config
toresourceDirectories in Compile
.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 themappings
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.