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")} )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With