-
-
Save bigtoast/1154501 to your computer and use it in GitHub Desktop.
sbt10 - generated sources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import sbt.Keys._ | |
object build extends Build { | |
lazy val generate = Project( | |
id = "source-gen", | |
base = file("."), | |
settings = Defaults.defaultSettings ++ generateSourceSettings | |
) | |
lazy val GenSourcesConfig = config("gen-sources-config").hide | |
lazy val genSources = TaskKey[Seq[File]]("gen-src") | |
lazy val outputDir = SettingKey[File]("output-dir") | |
lazy val generateSourceSettings: Seq[Project.Setting[_]] = inConfig(GenSourcesConfig)(Seq( | |
genSources <<= genSourcesTask, | |
outputDir <<= (sourceDirectory in Compile) {_ / "src_managed"}, | |
(managedSourceDirectories in Compile) <+= (outputDir in GenSourcesConfig).identity | |
))++ Seq(sourceGenerators in Compile <+= (genSources in GenSourcesConfig).identity) | |
def genSourcesTask = (streams, outputDir in GenSourcesConfig) map ((s, dir) => { | |
s.log.info("generating java sources") | |
val source = "package javapackage;\n\n" + | |
"public class GeneratedJavaClass {\n\n public String theString;\n}\n" | |
val outputFile = (dir / "GeneratedJavaClass.java").asFile | |
IO.write(outputFile, source) | |
//Seq(outputFile) in case you generate directly | |
(dir ** "*.java").get //in case your files are generated by an external process | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment