【问题标题】:Adding module dependency information in sbt's build.sbt file在 sbt 的 build.sbt 文件中添加模块依赖信息
【发布时间】:2015-08-28 15:52:22
【问题描述】:

我在 IntelliJ 中有一个多模块项目,如此屏幕截图所示,contexProcessor 模块依赖于 contextSummary 模块。

一旦我在项目结构中设置了依赖项,IntelliJ 就会处理所有事情。

但是,当我在build.sbt 中使用以下设置运行sbt test 时,我收到一个错误,抱怨它在 contextSummary 模块中找不到包。

name := "contextProcessor"

version := "1.0"

scalaVersion := "2.11.7"

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

如何教 sbt 找到缺失的模块?

【问题讨论】:

    标签: scala intellij-idea sbt


    【解决方案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

    如果只测试一个项目,我可以在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
    

    【讨论】:

      【解决方案2】:

      我认为一个简单的build.sbt 可能还不够。

      您需要像这样创建一个更复杂的 project/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"
      }
      

      【讨论】:

        猜你喜欢
        • 2014-09-18
        • 2020-01-01
        • 2019-02-12
        • 2012-04-18
        • 1970-01-01
        • 2017-09-16
        • 2016-10-23
        • 2017-04-28
        • 2020-12-08
        相关资源
        最近更新 更多