2015-08-28 65 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" 
}