Creating an SBT task to copy directories at compile time?

I'm new to the whole SBT and Scala scene, and I'm trying to create a project that uses the Java / Scala and Hibernate classes. I get a project to build perfectly - I just need to manually copy my hibernate configuration files to the target/scala<version>/classes folder so that they can be taken from sleep mode.

Is there a way to create a task in SBT to copy these folders to each compiler? 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) */ } 
+6
source share
1 answer

The most direct way to do this is to move files to ./src/main/resources/config .

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

 resourceDirectories in Compile <+= baseDirectory / "config" 

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

Want JAR packed files? Both of these answers will lead to this. You can remove them from mappings in packageBin to avoid this.

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

Source: https://habr.com/ru/post/899002/


All Articles