1

I have added this to my build.sbt:

resourceGenerators in Compile <+=
  (resourceManaged in Compile, name, version) map { (dir, n, v) =>
    val file = dir / "version"
    val contents = Process("git rev-parse HEAD").lines.head
    IO.write(file, contents)
    println("I have just been run")
    Seq(file)
  }

However it runs when I issue sbt run, not when issuing sbt compile. How can I make it run on compile? how can I troubleshoot it other than by disabling plugins? (disabling suspect plugins didn't solve...)

sbt version and plugins:

[info] This is sbt 0.13.5
[info] The current project is built against Scala 2.11.2
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, play.twirl.sbt.SbtTwirl, com.scalapenos.sbt.prompt.SbtPrompt, com.typesafe.sbteclipse.plugin.EclipsePlugin, com.typesafe.sbt.SbtStartScript, spray.revolver.RevolverPlugin, org.netbeans.nbsbt.plugin.NetBeansPlugin, com.typesafe.sbt.SbtScalariform, sbtbuildinfo.Plugin, com.typesafe.sbt.SbtGit
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
matanster
  • 15,072
  • 19
  • 88
  • 167
  • possible duplicate of [How to avoid re-compiling generated source code](http://stackoverflow.com/questions/24564118/how-to-avoid-re-compiling-generated-source-code) – 0__ Jan 29 '15 at 21:35
  • The generated source task doesn't run specifically on `run`, but on `compile`. `run` _depends_ on `compile`, and without further work, sbt wouldn't know that that generated source is cached somewhere, so it assumes it needs to recompile that source each time. See the linked question for a solution of caching generated sources. – 0__ Jan 29 '15 at 21:36
  • Thanks 0__. But my problem is different. It _doesn't_ at all run on compile! The resource only appears at the destination path when invoking "run", which is, awkward, but I triple verified that – matanster Jan 29 '15 at 22:06
  • This is not a duplicate guys – matanster Jan 29 '15 at 22:39
  • So you are saying that if you add a `println("HELLO")` before `val file` above, you don't see that text when you run `sbt compile`? Sounds _very odd_ to me. – 0__ Jan 29 '15 at 22:46
  • I already have a println there... that's how I concluded it's not running on `compile` and is running on `run`. Should it really be before `val file`? – matanster Jan 29 '15 at 23:06
  • The position shouldn't matter. Just early so we exclude that somehow you have an exception that it silently swallowed. – 0__ Jan 30 '15 at 00:01
  • I don't know, this is too wierd. I'll give it some rest and then have a fresh look. – matanster Jan 30 '15 at 00:34

0 Answers0