resourceGenerators in Compile does not run on compile (but does run on Run)
See original GitHub issuestart a new sbt project:
build.sbt:
resourceGenerators in Compile <+=
(resourceManaged in Compile, name, version) map { (dir, n, v) =>
println("saving git hash to resource - this should happen (only) upon compile")
val file = dir / "version"
val contents = Process("git rev-parse HEAD").lines.head
IO.write(file, contents)
Seq(file)
}
hw.scala:
object Hi {
def main(args: Array[String]) = {
println("Hi!")
val version = getClass.getResource("version")
println(s"running from git hash ${scala.io.Source.fromURL(version).mkString}")
}
}
Setup git:
git init
git add .
git commit -am "initial commit"
sbt compile it, you see only:
[info] Compiling 1 Scala source to target/scala-2.10/classes...
[success] Total time: 1 s, completed Jan 30, 2015 11:37:20 AM
sbt run it, you see:
saving git hash to resource - this should happen (only) upon compile
[info] Running Hi
Hi!
running from git hash 83931d8fec29fab2e26e7107b743adfd5d51df88
System setup:
Java HotSpot™ 64-Bit Server VM, Java 1.7.0_76)
[info] This is sbt 0.13.7 [info] The current project is built against Scala 2.10.4 [info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, com.typesafe.sbteclipse.plugin.EclipsePlugin [info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
(Ubuntu 14.04.1)
Related issues: https://github.com/sbt/sbt/issues/1046 https://github.com/sbt/sbt-buildinfo/issues/46 http://stackoverflow.com/questions/28223663/humane-guidance-for-sbt-dsl
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
sbt does not execute generators on compile - Stack Overflow
I have added this to my build.sbt: resourceGenerators in Compile <+= (resourceManaged in Compile, name, version) map { (dir, n, ...
Read more >sbt Reference Manual — Generating files
sbt provides standard hooks for adding source and resource generation tasks. ... Executing run (or package , not compile ) will add a...
Read more >sbt/sbt - Gitter
/home/arne/proj/tensorDslScala/build.sbt:36: error: No implicit for Append. ... but then why is resource generators not of type List[Task] and documented as ...
Read more ><+= operator in 0.13 - Google Groups
1) Is that operator in fact actually going away? ... resourceGenerators in Compile += myTaskKey.value // Error cannot run a task in a...
Read more >Generating files — sbt Documentation - Huihoo
Executing 'run' will print "Hi". Change Compile to Test to make it a test source. For efficiency, you would only want to generate...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is how we solved this:
compile
is being called@jsuereth You mentioned attaching triggers to the compile task, could you sketch what that would look like?