I also would like to know, how to define the custom scope, preferable in simple *.sbt build, not in project/*.scala build.推荐答案范围可以是项目、配置或任务.在这种情况下,我认为您希望定义自定义配置.The scope could be either project, configuration, or task. In this case, I think you're looking to define a custom configuration.已经有一个名为 IntegrationTest 的内置配置.您可以通过编写在构建定义中定义它:There's a built-in configuration called IntegrationTest already. You can define it in your build definition by writing:Defaults.itSettings这将使用与正常测试完全不同的设置,包括测试代码(进入 src/it/scala/)和库,所以这可能不是你想要的.This will use completely different setup from normal tests including the test code (goes into src/it/scala/) and libraries, so this may not be what you want.使用 sbt 0.13,您可以在 build.sbt 中定义如下自定义配置:Using sbt 0.13, you can define a custom configuration as follows in build.sbt:val TeamCity = config("teamcity") extend(Test)val root = project.in(file(".")). configs(TeamCity). settings(/* your stuff here */, ...)定义 teamcity:test现在你必须弄清楚如何定义teamcity:test.编辑:Mark Harrah 向我指出有相关文档.请参阅具有共享的其他测试配置来源.Edit: Mark Harrah pointed out to me that there's a documentation for this. See Additional test configurations with shared sources.添加单独的测试源(和编译)集的另一种方法是共享源.在这种方法中,源代码使用相同的类路径编译在一起并打包在一起. An alternative to adding separate sets of test sources (and compilations) is to share sources. In this approach, the sources are compiled together using the same classpath and are packaged together.综合起来val TeamCity = config("teamcity") extend(Test)val root = project.in(file(".")). configs(TeamCity). settings( name := "helloworld", libraryDependencies ++= Seq( "org.specs2" %% "specs2" % "2.2" % "test" ) ). settings(inConfig(TeamCity)(Defaults.testTasks ++ Seq( testOptions := Seq(Tests.Argument("nocolor")) )): _*)当您运行 teamcity:test 时,Specs2 输出显示没有颜色.When you run teamcity:test the Specs2 output displays without color. 这篇关于在 sbt 中定义自定义配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-07 03:46