为什么在编译时不执行自定义资源生成器? [英] Why doesn't a custom resourceGenerator get executed upon compile?
问题描述
我正在关注 How to 上的 SBT 文档生成资源试图在插件中获取一个资源生成器任务以在编译时运行.
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
)
}
我遇到过 sbt.plugin.JvmPlugin
正在重置 sourceGenerators in Compile
键的情况,这意味着我向它添加任务不会做任何事情除非我要求先加载 JvmPlugin
(正如我上面所做的那样).这里有没有类似的事情发生?
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?
推荐答案
任何添加到 Resource Generators 键的内容只会在实际需要时执行,例如在运行任务上.
Anything added to the Resource Generators key will only be executed when it is actually needed, on the run task for example.
这是用户错误,只是对 SBT 文档的误解.
This was user error and a misunderstanding of the SBT docs only.
这篇关于为什么在编译时不执行自定义资源生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!