Why doesn't a custom resourceGenerator get executed upon compile?

半城伤御伤魂 提交于 2019-12-24 12:14:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!