Subproject dependencies in SBT

家住魔仙堡 提交于 2019-12-11 07:29:13

问题


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)

}

回答1:


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")
  }

}


来源:https://stackoverflow.com/questions/6040245/subproject-dependencies-in-sbt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!