开发者

SBT sub-project inter-dependencies

开发者 https://www.devze.com 2023-01-31 22:09 出处:网络
Where have I gone wrong with this SBT project configuration? I have a parent project A, with subprojects B1 and B2, and B2 depends on project B1.

Where have I gone wrong with this SBT project configuration?

I have a parent project A, with subprojects B1 and B2, and B2 depends on project B1.

B1 compiles successfully; but B2's compilation fails because it cannot find B1's classes.

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 deliv开发者_如何学PythonerProjectDependencies = 
      B1.projectID :: super.deliverProjectDependencies.toList
  }
}

I'm really not sure if I've defined the dependency between B2 and B1 correctly. I would have specified it using the project method with this signature:

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

... but I need the subprojects to mix in the IdeaProject trait.


Well, you're using the other signature, though:

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

So, you need B2 to declare a dependency on B1.

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

Note: I'm pretty sure I'd rename the variables to not be the same as the class name here, because that just confuses me, and while it should work, that just seems funky.


Answering my own question in case someone else finds it useful. This folds in the solution provided by 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 {}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消