I'm writing a code generation plugin for sbt using the new AutoPlugin mechanism. I need to modify the sourceGenerators in Compile
setting but somehow it does not work when I do it from the plugin. After calling compile, nothing is printed on the screen.
However, if I take the line sourceGenerators in Compile <+= (mySourceGenerator in Compile)
and move it to the build.sbt
of the project suddenly the sourceGenerators in Compile
setting is modified and when I run the compile task the message is written to the screen.
Is there something I'm missing there? The code of the plugin is here:
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
}