I think I'm doing something like your first part in the following project: My module gen is the equivalent of your module A, and my module core is the equivalent of your module B. Without testing, the structure is roughly as follows:
// taking inspiration from
// http://stackoverflow.com/questions/11509843/
lazy val ugenGenerator = TaskKey[Seq[File]]("ugen-generate", "Generate UGen class files")
lazy val gen = Project(id = "gen", base = file("gen")) ...
lazy val core = Project(id = "core", base = file("core"))
.settings(
sourceGenerators in Compile <+= ugenGenerator in Compile,
ugenGenerator in Compile := {
val src = (sourceManaged in Compile ).value
val cp = (dependencyClasspath in Runtime in gen ).value
val st = streams.value
runUGenGenerator(description.value, outputDir = src,
cp = cp.files, log = st.log)
}
)
def runUGenGenerator(name: String, outputDir: File, cp: Seq[File],
log: Logger): Seq[File] = {
val mainClass = "my.class.from.Gen"
val tmp = java.io.File.createTempFile("sources", ".txt")
val os = new java.io.FileOutputStream(tmp)
log.info(s"Generating UGen source code in $outputDir for $name")
try {
val outs = CustomOutput(os)
val fOpt = ForkOptions(javaHome = None, outputStrategy = Some(outs), bootJars = cp,
workingDirectory = None, connectInput = false)
val res: Int = Fork.scala(config = fOpt,
arguments = mainClass :: "-d" :: outputDir.getAbsolutePath :: Nil)
if (res != 0) {
sys.error(s"UGen class file generator failed with exit code $res")
}
} finally {
os.close()
}
val sources = scala.io.Source.fromFile(tmp).getLines().map(file).toList
tmp.delete()
sources
}
This works in sbt 0.13, but I haven't had time to figure out why it doesn't work in 1.x.
By the way, how do I write sourceGenerators in Compile <+= ugenGenerator in Compile
without deprecated syntax?
lhs <+= foo
withlhs += foo.value
Anyway I am getting this when I try this:Error: Could not find or load main class scala.tools.nsc.MainGenericRunner java.lang.IllegalArgumentException: requirement failed: com.github.pathikrit.ResourceGenerator
– Heliacal