试图了解如何设置SBT subprojects。为我的所有子项目设置默认依赖项的正确方法是什么?

我尝试了这个,但是我的子项目没有选择任何依赖项(它们下载得很好)。

import sbt._

class MyProjects(info: ProjectInfo) extends DefaultProject(info)
{
  val projA = project("projA", "ProjectA")
  val projB = project("projB", "ProjectB")

  val akkaRepo = "Akka maven2 repo" at "http://www.scalablesolutions.se/akka/repository/"
  val multiverseRepo = "Multiverse maven2 repo" at "http://multiverse.googlecode.com/svn/maven-repository/releases/"
  val guiceyFruitRepo = "GuiceyFruit Maven2 repo" at "http://guiceyfruit.googlecode.com/svn/repo/releases/"
  val jBossRepo = "JBoss maven2 repo" at "https://repository.jboss.org/nexus/content/groups/public/"

  val junit = "junit" % "junit" % "4.5" % "test"
  val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"
  val akka = "se.scalablesolutions.akka" % "akka-core_2.8.0" % "0.10"
}

然后,基于this我尝试了以下操作。它起作用了,但这不是我期望要做的。为所有子项目设置默认依赖项不是更简单吗?
import sbt._

class MyProjects(info: ProjectInfo) extends DefaultProject(info)
{
  val projA = project("projA", "ProjectA", new Proj(_))
  val projB = project("projB", "ProjectB", new Proj(_))

  val akkaRepo = "Akka maven2 repo" at "http://www.scalablesolutions.se/akka/repository/"
  val multiversRepo = "Multiverse maven2 repo" at "http://multiverse.googlecode.com/svn/maven-repository/releases/"
  val guiceyFruitRepo = "GuiceyFruit Maven2 repo" at "http://guiceyfruit.googlecode.com/svn/repo/releases/"
  val jBossRepo = "JBoss maven2 repo" at "https://repository.jboss.org/nexus/content/groups/public/"

  class Proj(info:ProjectInfo) extends DefaultProject(info){
    val junit = "junit" % "junit" % "4.5" % "test"
    val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"
    val akka = "se.scalablesolutions.akka" % "akka-core_2.8.0" % "0.10"
  }
}

编辑:应该指出有一个better way来使用Akka,但是只是说明了我的观点。

最佳答案

使用继承和混合:

import sbt._

class ModularProject(info: ProjectInfo) extends DefaultProject(info){

    lazy val childProject = project("projA", "ProjectA",
        new DefaultProject(_)
            with Repositories
            with GlobalDependencies
            with AkkaDependencies)

    trait Repositories{
        lazy val akkaRepo = "Akka maven2 repo" at
        "http://www.scalablesolutions.se/akka/repository/"
        lazy val multiversRepo = "Multiverse maven2 repo" at
        "http://multiverse.googlecode.com/svn/maven-repository/releases/"
        lazy val guiceyFruitRepo = "GuiceyFruit Maven2 repo" at
        "http://guiceyfruit.googlecode.com/svn/repo/releases/"
        lazy val jBossRepo = "JBoss maven2 repo" at
        "https://repository.jboss.org/nexus/content/groups/public/"
    }

    trait GlobalDependencies{
        lazy val junit = "junit" % "junit" % "4.5" % "test"
        lazy val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"
    }

    trait AkkaDependencies{
        lazy val akka = "se.scalablesolutions.akka" % "akka-core_2.8.0" % "0.10"
    }

}

09-06 10:07