SBT 中的子项目依赖关系
我在 SBT 子项目上遇到了一个奇怪的问题,我认为这与依赖关系有关。这是我的设置:
- 我有一个包含两个子项目 A 和 B 的 SBT 项目。A
- 包含一个类和伴生对象
MyA
- B 依赖于 A。B
- 包含一个对象
MyB
,该对象具有一个主要方法。
当我尝试从 SBT 提示符执行 MyB
时,我在 MyA
上收到 NoSuchMethodError
。这不是 ClassNotFoundException
,但可能是因为它在类路径上看到了 MyA
类,而不是 MyA
对象。
作为健全性检查,我删除了 B 子项目并将其源代码移至 A 源代码树中。当我从 SBT 提示符运行 MyB
时,它按预期工作。
有没有人遇到过这个,或者我做错了什么明显的事情?
这是我的项目配置:
class MyProject(info: ProjectInfo) extends ParentProject(info) {
lazy val a = project("a", "a", new AProject(_))
lazy val b = project("b", "b", new BProject(_), a)
object Dependencies {
lazy val scalaTest = "org.scalatest" % "scalatest_2.9.0" % "1.4.1" % "test"
}
class AProject(info: ProjectInfo) extends DefaultProject(info) with AutoCompilerPlugins {
val scalaTest = Dependencies.scalaTest
val continuationsPlugin = compilerPlugin("org.scala-lang.plugins" % "continuations" % "2.9.0")
override def compileOptions = super.compileOptions ++ compileOptions("-P:continuations:enable") ++ compileOptions("-unchecked")
}
class BProject(info: ProjectInfo) extends DefaultProject(info)
}
I am having a strange problem with SBT subprojects which I think is dependency related. Here's my setup:
- I have an SBT project with two subprojects A and B.
- A contains a class and companion object
MyA
- B depends on A.
- B contains an object
MyB
which has a main method.
When I try to execute MyB
from the SBT prompt, I get a NoSuchMethodError
on MyA
. This is not a ClassNotFoundException
, but maybe it's happening because it sees the MyA
class on the classpath, but not the MyA
object.
As a sanity check, I dropped the B subproject and moved its source into the A source tree. When I run MyB
from the SBT prompt, it works as expected.
Has anyone run into this, or am I doing something obviously wrong?
Here is my project configuration:
class MyProject(info: ProjectInfo) extends ParentProject(info) {
lazy val a = project("a", "a", new AProject(_))
lazy val b = project("b", "b", new BProject(_), a)
object Dependencies {
lazy val scalaTest = "org.scalatest" % "scalatest_2.9.0" % "1.4.1" % "test"
}
class AProject(info: ProjectInfo) extends DefaultProject(info) with AutoCompilerPlugins {
val scalaTest = Dependencies.scalaTest
val continuationsPlugin = compilerPlugin("org.scala-lang.plugins" % "continuations" % "2.9.0")
override def compileOptions = super.compileOptions ++ compileOptions("-P:continuations:enable") ++ compileOptions("-unchecked")
}
class BProject(info: ProjectInfo) extends DefaultProject(info)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,在项目 B 上启用延续插件时出现问题。这是我的工作配置:
It turns out to have been a problem enabling the continuations plugin on project B. Here's my working configuration: