问题
I'm following the SBT docs on How to generate resources trying to get a resourceGenerator task in a plugin to run on compile.
It's as simple as you see in the docs:
object TestResourcePlugin extends AutoPlugin {
import SbtWeb.autoImport._
import WebKeys._
override def requires = SbtWeb && plugins.JvmPlugin
override def trigger = AllRequirements
override def projectSettings = Seq(
resourceGenerators in Compile += Def.task {
val file = (resourceManaged in Compile).value / "demo" / "test"
val contents = "test file"
IO.write(file, contents)
Seq(file)
}.taskValue
)
}
I've encountered a situation where the sbt.plugin.JvmPlugin
was resetting the sourceGenerators in Compile
key, meaning my adding a task to it wouldn't do anything unless I had required the JvmPlugin
to be loaded first (as I am doing above). Is there something similar happening here?
回答1:
Anything added to the Resource Generators key will only be executed when it is actually needed, on the run task for example.
This was user error and a misunderstanding of the SBT docs only.
来源:https://stackoverflow.com/questions/25125063/why-doesnt-a-custom-resourcegenerator-get-executed-upon-compile