How do I specify a config file with sbt 0.12.2 for sbt test?

前端 未结 2 483
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 08:33

I have a Play! project with unit tests and I am trying to run tests on my staging environment using sbt. Before I upgraded to Play 2.1, when I was using Play 2.0.4 and sbt 0

相关标签:
2条回答
  • 2020-12-15 08:58

    test is using forked jvm. Use javaOptions sbt setting to pass jvm options to it e.g.

    javaOptions ++= Seq("-Dconfig.file=conf/staging.conf")
    or

    javaOptions ++= collection.JavaConversions.propertiesAsScalaMap(System.getProperties).map{ case (key,value) => "-D" + key + "=" +value }.toSeq

    0 讨论(0)
  • 2020-12-15 09:00

    Similar approach is to just pass the config file to use, while triggering the sbt test

    First, in the Build.scala file

    val testOptions = "-Dconfig.file=conf/" + Option(System.getProperty("test.config")).getOrElse("application") + ".conf"
    
    val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
        javaOptions in Test += testOptions
    )
    

    Then, in the command line to run the test with integ.conf

    sbt -Dtest.config=integ test
    

    to use the default application.conf

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