SBT 子项目相互依赖关系

发布于 2024-10-08 18:58:58 字数 943 浏览 6 评论 0原文

我这个 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 特征中。

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 deliverProjectDependencies = 
      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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月蹉跎了容颜 2024-10-15 18:58:58

好吧,不过,您正在使用另一个签名:

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)

注意:我很确定我会将变量重命名为与此处的类名不同,因为这让我感到困惑,虽然它应该可以工作,但这看起来很时髦。

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.

触ぅ动初心 2024-10-15 18:58:58

回答我自己的问题以防其他人觉得有用。这在 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 {}
}

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 {}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文