我在IntelliJ中有一个多模块项目,如此屏幕截图所示,contexProcessor模块依赖于contextSummary模块。
一旦我在Project Structure中设置了依赖项,IntelliJ就会处理所有事情。
但是,当我在sbt test
中使用以下设置运行build.sbt
时,我收到错误,抱怨它无法在contextSummary模块中找到包。
name := "contextProcessor"
version := "1.0"
scalaVersion := "2.11.7"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.2" % "test"
如何教导找到丢失的模块?
答案 0 :(得分:1)
我可以使用主根目录中的build.sbt
文件。
lazy val root = (project in file(".")).aggregate(contextSummary, contextProcessor)
lazy val contextSummary = project
lazy val contextProcessor = project.dependsOn(contextSummary)
参考:http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Multi-Project.html
仅测试一个项目,我可以在project
中使用sbt
命令。
> sbt
[info] Set current project to root (in build file:/Users/smcho/Desktop/code/ContextSharingSimulation/)
> project contextProcessor
[info] Set current project to contextProcessor (in build file:/Users/smcho/Desktop/code/ContextSharingSimulation/)
> test
对于批处理模式,如How to pass command line args to program in SBT 0.13.1?
sbt "project contextProcessor" test
答案 1 :(得分:0)
我认为一个简单的build.sbt
可能还不够。
你需要创建一个更复杂的项目/ Build.scala :
import sbt._
import sbt.Keys._
object Build extends Build {
lazy val root = Project(
id = "root",
base = file("."),
aggregate = Seq(module1, module2)
)
lazy val module1 = Project(
id = "module1",
base = file("module1-folder"),
settings = Seq(
name := "Module 1",
version := "1.0",
scalaVersion := "2.11.7",
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.2" % "test"
lazy val module2 = Project(
id = "module2",
base = file("module2-folder"),
dependencies = Seq(module1),
settings = Seq(
name := "Module 2",
version := "1.0",
scalaVersion := "2.11.7",
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.2" % "test"
}