SBT 中的子项目依赖关系

发布于 2024-11-08 03:00:01 字数 1279 浏览 4 评论 0原文

我在 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 技术交流群。

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

发布评论

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

评论(1

许一世地老天荒 2024-11-15 03:00:01

事实证明,在项目 B 上启用延续插件时出现问题。这是我的工作配置:

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) with AutoCompilerPlugins {
    override def compileOptions = super.compileOptions ++ compileOptions("-P:continuations:enable") ++ compileOptions("-unchecked")
  }

}

It turns out to have been a problem enabling the continuations plugin on project B. Here's my working 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) with AutoCompilerPlugins {
    override def compileOptions = super.compileOptions ++ compileOptions("-P:continuations:enable") ++ compileOptions("-unchecked")
  }

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