How to copy some files to the build target directory with SBT?

前端 未结 2 1875
故里飘歌
故里飘歌 2021-01-04 19:18

How can I copy some source files (e.g. /src/main/html/*.html) to the build output directory (e.g. /target/scala-2.11/) with SBT so that the files e

2条回答
  •  别那么骄傲
    2021-01-04 20:05

    You can define sbt task copying resources to target directory:

    lazy val copyRes = TaskKey[Unit]("copyRes")
    
    lazy val root:Project = Project(
       ...
    )
    .settings(
      ...
      copyRes <<= (baseDirectory, target) map {
        (base, trg) => new File(base, "src/html").listFiles().foreach(
          file => Files.copy(file.toPath, new File(trg, file.name).toPath)
        )
      }
    )
    

    and use this task in sbt:

    sbt clean package copyRes
    

提交回复
热议问题