define custom configuration in sbt

前端 未结 1 1285
北恋
北恋 2020-12-19 03:46

I want to set another set of options for running tests in integration server and in dev environment.

Let\'s have this option:

testOptions := Seq(Test         


        
相关标签:
1条回答
  • 2020-12-19 04:27

    The scope could be either project, configuration, or task. In this case, I think you're looking to define a custom configuration.

    using itSettings

    There's a built-in configuration called IntegrationTest already. You can define it in your build definition by writing:

    Defaults.itSettings
    

    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.

    defining your own configuration

    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 */, ...) 
    

    defining teamcity:test

    Now you have to figure out how to define teamcity:test.

    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.

    putting it all 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"))
      )): _*)
    

    When you run teamcity:test the Specs2 output displays without color.

    0 讨论(0)
提交回复
热议问题