title: SBT incorrect order of compilation
body: <p>TL/DR: Checkout last two commits and run <code>sbt clean compile</code>: <a href="https://github.com/mirelon/akka-in-action/tree/json/chapter2" rel="nofollow">https://github.com/mirelon/akka-in-action/tree/json/chapter2</a></p>
  
  <p>There is RestInterface.scala:</p>
  
  <pre><code>package com.goticks
  
  import akka.actor._
  
  import spray.routing._
  import spray.http.StatusCodes
  import spray.httpx.SprayJsonSupport._
  import spray.routing.RequestContext
  import akka.util.Timeout
  import scala.concurrent.duration._
  import scala.language.postfixOps
  
  class RestInterface extends HttpServiceActor
                      with RestApi {
    def receive = runRoute(routes)
  }
  
  trait RestApi extends HttpService { actor: Actor =&gt;
    import context.dispatcher
    import com.goticks.TicketProtocol._
  
    implicit val timeout = Timeout(10 seconds)
    import akka.pattern.ask
  
    def routes: Route =
  
      path("events") {
        get { requestContext =&gt;
          context.actorOf(Props[Resu]).ask(GetEvents)
        }
      }
  
  }
  
  class Responder(requestContext:RequestContext) extends Actor {
    import TicketProtocol._
  
    def receive = {
  
      case Events(events) =&gt;
        requestContext.complete(StatusCodes.OK, events)
        self ! PoisonPill
  
    }
  }
  </code></pre>
  
  <p>and Resu.scala (note that Resu is alphabetically after RestInterface)</p>
  
  <pre><code>package com.goticks
  
  import akka.actor.Actor
  
  class Resu extends Actor {
    import TicketProtocol._
    import spray.json._
  
    def receive = {
  
      case GetEvents =&gt; {
        println(Event(event = "E").toJson)
      }
    }
  }
  
  object TicketProtocol {
    import spray.json._
  
    case class Event(event:String)
  
    case object GetEvents
  
    case class Events(events:List[Event])
  
    object Event extends DefaultJsonProtocol {
      implicit val format = jsonFormat1(Event.apply)
    }
  
  }
  </code></pre>
  
  <p>build.sbt:</p>
  
  <pre><code>name := "goticks"
  
  version := "0.1-SNAPSHOT"
  
  organization := "com.goticks"
  
  scalaVersion := "2.11.1"
  
  libraryDependencies ++= {
    val akkaVersion = "2.3.4"
    val sprayVersion = "1.3.1"
    Seq(
      "com.typesafe.akka" %% "akka-actor" % akkaVersion,
      "io.spray" %% "spray-can" % sprayVersion,
      "io.spray" %% "spray-routing" % sprayVersion,
      "io.spray" %% "spray-json" % "1.2.6"
    )
  }
  </code></pre>
  
  <p>build.properties;</p>
  
  <pre><code>sbt.version=0.13.7
  </code></pre>
  
  <p>plugins.sbt:</p>
  
  <pre><code>resolvers += Classpaths.typesafeResolver
  
  resolvers += "sbt-idea" at "http://mpeltonen.github.com/maven/"
  
  addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
  
  addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
  
  addSbtPlugin("com.typesafe.sbt" % "sbt-start-script" % "0.10.0")
  
  addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.3.8")
  </code></pre>
  
  <h2>Compilation issue</h2>
  
  <p>When I run <code>sbt clean compile</code>, everything is ok. But when I refactor the <code>Resu</code> class into <code>Ress</code> (note that <code>Ress</code> is alphabetically before <code>RestInterface</code>) (also rename its file, the diff can be viewed here: <a href="https://github.com/mirelon/akka-in-action/commit/583ca801fb7d1564024eee2f98d57f03ecacc6e5" rel="nofollow">https://github.com/mirelon/akka-in-action/commit/583ca801fb7d1564024eee2f98d57f03ecacc6e5</a>), then there is a compilation error:</p>
  
  <pre><code>[error] /home/miso/IdeaProjects/akka-in-action/chapter2/src/main/scala/com/goticks/Ress.scala:12: Cannot find JsonWriter or JsonFormat type class for com.goticks.TicketProtocol.Event
  [error]       println(Event(event = "E").toJson)
  [error]                                  ^
  [error] one error found
  [error] (compile:compile) Compilation failed
  </code></pre>
  
  <p>Clearly there is an implicit json writer missing. Could it be due to incorrect order of compiling? Could sbt compile the classes in alphabetical order, ignoring imports?</p>