gpt4 book ai didi

scala - 使用 SBT 子项目和 Scala 玩 2.2.2

转载 作者:行者123 更新时间:2023-12-02 01:50:48 27 4
gpt4 key购买 nike

我正在尝试使用 Play 2.2.2 和 SBT 0.13.1 设置多模块开发环境

我的项目结构是这样的:

myProject
└ build.sbt
└ app - this code works perfect
└ modules
└ testModule
└ build.sbt
└ src
└ main
└ scala - here I have simple object Foo with method which returns string
└ test
└ scala - here is Spec2 test for Foo object with JUnitRunner
└ test - here is Spec2 tests for app and these tests also works fine

根目录中的 build.sbt 包含:

import play.Project._

name := "FooBar"

version := "1.0"

playScalaSettings

lazy val main = project.in(file("."))
.dependsOn(testModule).aggregate(testModule)

lazy val testModule = project.in(file("modules/testModule"))

模块中的 build.sbt 仅包含:

import play.Project._

name := "FooBar-module"

playScalaSettings

当我尝试使用 testModule 中的代码时,编译器告诉我它甚至无法从该模块中找到包。在运行测试时我也得到了

No tests to run for testModule/test:test

但是如果我在 testModule 中写了无效的代码,我会开始从这个模块中得到错误,所以模块肯定是编译过的。

这里可能有什么问题? SBT 配置看起来正确

最佳答案

playScalaSettings包含大多数路径的设置。这包括将测试源设置为路径 /test(参见 default settings in doc)。然而,在您的布局中,测试源位于 src/test 中。所以 sbt 不会在测试中寻找这些文件。

如果您的模块是一个 Play 项目,则相应地更改文件夹布局或配置路径以匹配您的布局。如果没有删除 playScalaSettings 行。

你可以这样设置测试源路径:

scalaSource in Test <<= baseDirectory / "src" / "test" / "scala"

关于scala - 使用 SBT 子项目和 Scala 玩 2.2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22891905/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com