我正在使用新的 AutoPlugin 机制为 sbt 编写代码生成插件。我需要修改sourceGenerators in Compile
设置,但不知何故,当我从插件中进行操作时它不起作用。调用 compile 后,屏幕上没有打印任何内容。
但是,如果我突然将这条线sourceGenerators in Compile <+= (mySourceGenerator in Compile)
移到项目的位置,则设置会被修改,并且当我运行编译任务时,消息会写入屏幕。build.sbt
sourceGenerators in Compile
那里有我想念的东西吗?插件的代码在这里:
package net.lopezbobeda.plugin
import sbt._
import Keys._
import java.io.{ File, Writer }
object MyPlugin extends AutoPlugin {
// by defining autoImport, the settings are automatically imported into user's `*.sbt`
object autoImport {
// configuration points, like the built-in `version`, `libraryDependencies`, or `compile`
lazy val mySourceGenerator = taskKey[Seq[File]]("Generate")
// default values for the tasks and settings
lazy val baseXtendPluginSettings: Seq[Def.Setting[_]] = Seq(
mySourceGenerator in Compile := {
val s: TaskStreams = streams.value
s.log.info("Generating! " + sourceManaged.value)
Nil
},
sourceGenerators in Compile <+= (mySourceGenerator in Compile) // if I put this line in build.sbt everything works as expected.
)
}
override def trigger = allRequirements
import autoImport._
override val projectSettings = baseXtendPluginSettings
}