SBT子项目相互依赖

时间:2010-12-24 15:20:10

标签: scala dependencies sbt

这个SBT项目配置出了什么问题?

我有一个父项目A,子项目B1和B2,B2取决于项目B1。

B1编译成功;但是B2的编译失败了,因为它无法找到B1的类。

import sbt._

class A(info: ProjectInfo) extends ParentProject(info) with IdeaProject {
  lazy val B1 = project("b1", "B1", new B1(_))
  lazy val B2 = project("b2", "B2", new B2(_))

  class B1(info: ProjectInfo) extends DefaultWebProject(info) with IdeaProject {
    override def unmanagedClasspath = super.unmanagedClasspath +++ extraJars
    def baseDirectory = "lib"
    def extraJars = descendents(baseDirectory, "*.jar")
  }

  class B2(info: ProjectInfo) extends DefaultProject(info) with IdeaProject {
    override def deliverProjectDependencies = 
      B1.projectID :: super.deliverProjectDependencies.toList
  }
}

我真的不确定我是否正确定义了B2和B1之间的依赖关系。我会使用带有此签名的项目方法指定它:

def project(path: Path, name: String, deps: Project*): Project

...但我需要将子项目混合在IdeaProject特征中。

2 个答案:

答案 0 :(得分:4)

嗯,你正在使用其他签名:

def project [P <: Project](path : Path, name : java.lang.String, construct : (ProjectInfo) => P, deps : Project*) : P

因此,您需要B2来声明对B1的依赖。

lazy val B2 = project("b2", "B2", new B2(_), B1)

注意:我很确定我会在这里将变量重命名为与类名不同,因为这只会让我感到困惑,虽然它应该有效,但这看起来很时髦。

答案 1 :(得分:2)

回答我自己的问题以防其他人发现它有用。这在Tristan Juricek提供的解决方案中有所体现:

import sbt._

class ActiveMinutesProject(info: ProjectInfo) extends ParentProject(info) with IdeaProject {
  lazy val amweb = project("amweb", "ActiveMinutes web application", new AMWeb(_))
  lazy val amadmin = project("amadmin", "ActiveMinutes administration", new AMAdmin(_), amweb)

  class AMWeb(info: ProjectInfo) extends DefaultWebProject(info) with IdeaProject {
    override def unmanagedClasspath = super.unmanagedClasspath +++ extraJars
    def baseDirectory = "lib"
    def extraJars = descendents(baseDirectory, "*.jar")
  }

  class AMAdmin(info: ProjectInfo) extends DefaultProject(info) with IdeaProject {}
}
相关问题