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 特征中。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,不过,您正在使用另一个签名:
因此,您需要 B2 来声明对 B1 的依赖关系。
注意:我很确定我会将变量重命名为与此处的类名不同,因为这让我感到困惑,虽然它应该可以工作,但这看起来很时髦。
Well, you're using the other signature, though:
So, you need B2 to declare a dependency on 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.
回答我自己的问题以防其他人觉得有用。这在 Tristan Juricek 提供的解决方案中得到体现:
Answering my own question in case someone else finds it useful. This folds in the solution provided by Tristan Juricek: