2015-08-28 66 views
0

添加模塊依賴信息我在的IntelliJ一個多模塊項目,在這個屏幕截圖顯示,contexProcessor模塊依賴contextSummary模塊。在SBT的build.sbt文件

的IntelliJ照顧一切在項目結構的依賴性,一旦我設置。

enter image description here

然而,當我在build.sbt以下設置運行sbt test,我得到了一個錯誤,抱怨它無法找到contextSummary模塊中的包。

name := "contextProcessor" 

version := "1.0" 

scalaVersion := "2.11.7" 

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.2" % "test" 

enter image description here

如何教SBT,失蹤的模塊被發現?

回答

0

我可以使用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

爲了測試只有一個項目,我可以在sbt使用project命令。

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