Reputation: 2755
Based on sbt 0.11.0 documentation available ("Common Tasks" wiki page and others) and after seeing how this is done in Scalaz SBT build and in Scalate SBT build I can't figure out why my simple example does not work:
import sbt._
import Keys._
object MyBuild extends Build {
lazy val project = Project(
id = "root",
base = file("."),
settings = Defaults.defaultSettings ++ Seq(
(sourceGenerators in Compile) <+= (sourceManaged in Compile) map { dir =>
val file = dir / "bla.scala"
IO.write(file, """object Bla extends App { println("bla!") }""")
Seq(file)
}
)
)
}
Putting that on project/build.scala of an empty project and running "sbt compile" generates/compiles nothing and "sbt run" complains that it can not find any main class.
Now, if I put the setting in the "quick configuration" build.sbt as follows instead of the full configuration as above, it just works.
(sourceGenerators in Compile) <+= (sourceManaged in Compile) map { dir =>
val file = dir / "bla.scala"
IO.write(file, """object Bla extends App { println("bla!") }""")
Seq(file)
}
Obviously, needing to create a build.sbt file in a "full configuration"-only project is far from desirable, at least for me.
So, why this setting is not working in the full configuration?
Upvotes: 26
Views: 698
Reputation: 2399
Just copy paste your code in file project/Build.scala
and run it with sbt run
and that works.
Are your sure that your Build.scala
is correctly located (must be in project
directory) ?
Upvotes: 2