title: Defining sbt task that invokes method from project code?
body: <p>I'm using SBT to build a scala project. I want to define a very simple task, that when I input <code>generate</code> in sbt:</p>
  
  <pre><code>sbt&gt; generate
  </code></pre>
  
  <p>It will invoke my <code>my.App.main(..)</code> method to generate something.</p>
  
  <p>There is a <code>App.scala</code> file in <code>myproject/src/main/scala/my</code>, and the simplified code is like this:</p>
  
  <pre><code>object App {
     def main(args: Array[String]) {
         val source = readContentOfFile("mysource.txt")
         val result = convert(source)
         writeToFile(result, "mytarget.txt");
     }
     // ignore some methods here
  }
  </code></pre>
  
  <p>I tried to add following code into <code>myproject/build.sbt</code>:</p>
  
  <pre><code>lazy val generate = taskKey[Unit]("Generate my file")
  
  generate := {
    my.App.main(Array())
  }
  </code></pre>
  
  <p>But which doesn't compile since it can't find <code>my.App</code>.</p>
  
  <p>Then I tried to add it to <code>myproject/project/build.scala</code>:</p>
  
  <pre><code>import sbt._
  import my._
  
  object HelloBuild extends Build {
  
    lazy val generate = taskKey[Unit]("Generate my file")
  
    generate := {
      App.main(Array())
    }
  
  }
  </code></pre>
  
  <p>But it still can't be compiled, that it can't find package <code>my</code>.</p>
  
  <p>How to define such a task in SBT?</p>