简体   繁体   English

ScalaTest 多项目 sbt 所需的设置

[英]ScalaTest needed settings with multi-project sbt

I neither can run test becauses any of them are detected and when compilator complains it's to explain me that i can't import classes from /core/src/main in /core/src/test when im interactively running sbt in core project.我既不能运行测试,因为它们中的任何一个都被检测到,并且当编译器抱怨它是为了解释我当我在核心项目中以交互方式运行 sbt 时,我无法从 /core/src/test 中的 /core/src/main 导入类。

Here is the basic configuration i'm using.这是我正在使用的基本配置。

Folder organization文件夹组织

|
| build.sbt
|
|-------------- core | src ------------| main | scala | files...
|                    | build.sbt       | test | scala | files...
|
|-------------- proj1 | src ----------- | main | scala | files...
|                     | build.sbt       | test | scala | files...

Here some peace of the build.sbt这里有些和平。sbt


lazy val deps = Seq(
    "org.scalactic" %% "scalactic" % "3.1.2",
    "org.scalatest" %% "scalatest" % "3.1.2" % "test"
)

lazy val coreDeps = libraryDependencies ++= deps


lazy val core = (project in file("core"))
   .settings(coreDeps)

lazy val proj1 = (project in file("proj1"))
  .settings(coreDeps)
  .dependsOn(core)

Problem came from build.sbt files which were under core and proj1 once i remove them, everything works as expected.问题来自 build.sbt 文件,这些文件在coreproj1下,一旦我删除它们,一切都按预期工作。

You just need to do what it says in the comment: apply the settings using the settings method:您只需要按照评论中的说明进行操作:使用settings方法应用设置:

lazy val core = (project in file("core"))
  .settings(
    libraryDependencies ++= Seq(
      "org.scalactic" %% "scalactic" % "3.1.2",
      "org.scalatest" %% "scalatest" % "3.1.2" % "test"
    )
  )

lazy val proj1 = (project in file("proj1"))
  .settings(
    libraryDependencies ++= Seq(
      "org.scalactic" %% "scalactic" % "3.1.2",
      "org.scalatest" %% "scalatest" % "3.1.2" % "test"
    )
  )

Alternatively, you can scope the libraryDependencies key to ThisBuild .或者,您可以 scope 将libraryDependencies键设置为ThisBuild Then it will be inherited in all the subprojects:那么它将在所有子项目中被继承:

ThisBuild / libraryDependencies ++= Seq(
  "org.scalactic" %% "scalactic" % "3.1.2",
  "org.scalatest" %% "scalatest" % "3.1.2" % "test"
)

lazy val core = (project in file("core"))
lazy val proj1 = (project in file("proj1"))

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

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