简体   繁体   English

在多项目Build.sbt中保存库依赖项

[英]Factoring libraryDependencies in multi project Build.sbt

I'm trying to write a concise multi project Build.sbt, so I tried to put all library dependencies in root project and then make others depends on it. 我正在尝试编写一个简洁的多项目Build.sbt,所以我尝试将所有库依赖项放在根项目中,然后让其他项依赖它。 My Build.sbt looks like the following: 我的Build.sbt如下所示:

object KataBuild extends Build {

        lazy val fizzBuzz = Project(
            id = "fizzBuzz", 
            base = file("fizzBuzz"),
            settings = Project.defaultSettings ++ Seq(
                name := "fizzBuzz",
                version := "1.0",
                scalaVersion := "2.10.3"
            )
        )

        lazy val kata = Project(
            id = "scala-kata", 
            base = file("."),
            settings = Project.defaultSettings ++ Seq(
                name := "scala-kata",
                version := "1.0",
                scalaVersion := "2.10.3",
                libraryDependencies ++= Seq(
                    "org.scalatest" %% "scalatest" % "2.1.0" % "test"
                )
            )
        ) aggregate(fizzBuzz)

        fizzBuzz dependsOn(kata)

}

But running test from the main project (scala-kata) fails to build test for fizzBuzz. 但是从主项目(scala-kata)运行测试无法为fizzBu​​zz构建测试。 What am I missing? 我错过了什么?

Your question is similar to this one . 你的问题和这个问题类似。 In short, fizzBuzz.dependsOn(kata) means that its compile configuration depends on the kata's compile configuration, but you want to link the test configurations. 简而言之, fizzBuzz.dependsOn(kata)意味着它的编译配置取决于kata的编译配置,但是您想要链接测试配置。

The 'Per-configuration classpath dependencies' section of the sbt docs show you how you can make a test->test dependency instead. sbt文档的“按配置类路径依赖关系”部分向您展示如何制作test->test依赖项。


However, if you are not going to use kata 's test sources but are just looking for a way to include Scala-Test in fizzBuzz , just add it explicitly to fizzBuzz 's library dependencies, too. 但是,如果您不打算使用kata的测试源,而只是想在fizzBuzz包含Scala-Test的fizzBuzz ,那么只需将它显式添加到fizzBuzz的库依赖项中。 You can define a helper value 您可以定义辅助值

lazy val scalaTest = "org.scalatest" %% "scalatest" % "2.1.0" % "test"

Then you can add it to be sub project's library dependencies ( libraryDependencies += scalaTest ). 然后,您可以将其添加为子项目的库依赖项( libraryDependencies += scalaTest )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM