Mikaël Mayer
Mikaël Mayer

Reputation: 10711

Prevent looping recompilation in SBT

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?

Upvotes: 2

Views: 735

Answers (1)

mavarazy
mavarazy

Reputation: 7735

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" }

Upvotes: 5

Related Questions