Skip to content

Instantly share code, notes, and snippets.

@Milyardo
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Milyardo/8fa5b30280fdcd9f572f to your computer and use it in GitHub Desktop.
Save Milyardo/8fa5b30280fdcd9f572f to your computer and use it in GitHub Desktop.
SBT Post compile source generator.
object GeneratorPlugin extends AutoPlugin {
object autoImport {
val generateSource = TaskKey[Seq[File]]("genmysources","Generates sources")
}
import autoImport._
lazy val MyGenerator = config("my-generator").extend(Compile)
override lazy val projectSettings = Seq[Def.Setting[_]](
ivyConfigurations += MyGenerator
) ++ fromScope(Compile)
def fromScope(scope: Configuration) = inConfig(MyGenerator)(Defaults.configSettings ++ Seq[Def.Setting[_]](
classDirectory := (classDirectory in scope).value //I've worked around MyGenerator grating it's own artifact by setting
//classDirectory like so
sourceManaged := (sourceManaged in scope).value / "myGeneratedSources",
val generateSource <<= (javaHome, compilerClasspath,
fullClasspath in scope, classDirectory,
sourceManaged, streams) map (doGenerateSources),
sourceGenerators += generateSource.taskValue
)
def doGenerateSources = ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment