SBT中的子项目依赖关系 [英] Subproject dependencies in SBT

查看:185
本文介绍了SBT中的子项目依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,SBT子项目,我认为是依赖关联。这是我的设置:




  • 我有一个具有两个子项目A和B的SBT项目。

  • A包含一个类和伴侣对象 MyA

  • B取决于A。

  • B包含对象 MyB 其主要方法。



当我尝试执行 MyB 从SBT提示符,我得到一个 NoSuchMethodError MyA 。这不是一个 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 =项目(b,b,新的BProject(_),a)

对象依赖关系{
lazy val scalaTest =org.scalatest%scalatest_2.9.0% 1.4.1%测试
}

class AProject(info:ProjectInfo)使用AutoCompilerPlugins扩展DefaultProject(info){
val scalaTest = Dependencies.scalaTest
val connectationsPlugin = compilerPlugin(org.scala-lang.plugins%continuation%2.9.0)
override def compileOptions = super.compileOptions ++ compileOptions( - P:继续:启用)+ + compileOptions( - unchecked)
}

class BProject(info:ProjectInfo)exte nds DefaultProject(info)

}


解决方案

  class MyProject (info:ProjectInfo)extends ParentProject(info){

lazy val a = project(a,a,new AProject(_))
lazy val b = project b,b,新的BProject(_),a)

对象依赖关系{
lazy val scalaTest =org.scalatest%scalatest_2.9.0%1.4.1 %test
}

class AProject(info:ProjectInfo)使用AutoCompilerPlugins扩展DefaultProject(info){
val scalaTest = Dependencies.scalaTest
val continuementsPlugin =编译器插件(org.scala-lang.plugins%连续%2.9.0)
override def compileOptions = super.compileOptions ++ compileOptions( - P:继续:启用)++ compileOptions -unchecked)
}

class BProject(info: ProjectInfo)使用AutoCompilerPlugins扩展了DefaultProject(info){
override def compileOptions = super.compileOptions ++ compileOptions( - P:继续:启用)++ compileOptions( - unchecked)
}

}


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)

}

解决方案

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

}

这篇关于SBT中的子项目依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆