26

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?

Pablo Lalloni
  • 2,615
  • 19
  • 20
  • I copied and pasted the above into project/Build.scala, ran 'sbt run', and it printed bla! as expected. Perhaps check that the filename is right and that the definition is getting loaded by throwing in a println in the object or by changing a setting and verifying it takes effect. – Mark Harrah Oct 13 '11 at 02:55
  • Does `project/build.scala` fail where `project/Build.scala` succeeds? – earldouglas Nov 25 '11 at 01:26
  • this guy well deserves a massive down-vote for keeping the answer not accepted for a year. let me be the first one :) – Anton Kraievyi Mar 19 '13 at 07:45

1 Answers1

2

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) ?

David
  • 2,399
  • 20
  • 17