1

I am using SBT to build my scala project. AFter the compilation of a submodule which sues fastOptJS, I need to push the compiled files to another module within the same project, I designed a custom command fastOptCopy to do so.

lazy val copyjs = TaskKey[Unit]("copyjs", "Copy javascript files to public directory")
copyjs := {
  val outDir = baseDirectory.value / "public/js"
  val inDir = baseDirectory.value / "js/target/scala-2.11"
  val files = Seq("js-fastopt.js", "js-fastopt.js.map", "js-jsdeps.js") map { p => (inDir / p, outDir / p) }
  IO.copy(files, true)
}

addCommandAlias("fastOptCopy", ";fastOptJS;copyjs")

However, when I enter into the sbt console and type

~fastOptCopy

it keeps compiling, copying, compiling, copying, ... in an infinite loop. I guess that because I am copying the files, it thinks that the sources have changed and retriggers compilation.

How can I prevent this?

Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101

1 Answers1

5

You can exclude specified files from watchSources in sbt configuration

http://www.scala-sbt.org/0.13/docs/Triggered-Execution.html

watchSources defines the files for a single project that are monitored for changes. By default, a project watches resources and Scala and Java sources.

Here is a similar question: How to not watch a file for changes in Play Framework

watchSources := watchSources.value.filter { _.getName != "BuildInfo.scala" }
Community
  • 1
  • 1
mavarazy
  • 7,562
  • 1
  • 34
  • 60
  • Following your example, I used the following command `watchSources := watchSources.value.filter ( source => Seq("js-fastopt.js", "js-fastopt.js.map", "js-jsdeps.js").indexOf(source.getName) == -1 )` which worked perfectly. Thanks ! – Mikaël Mayer Aug 10 '15 at 14:10