Setting system properties with “sbt run”

后端 未结 4 2013
灰色年华
灰色年华 2020-12-29 06:52

I\'m using a pretty recent version of SBT (seems to be hard to figure out what the version is). I want to pass system properties to my application with sbt run

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 07:36

    I found the best way to be adding this to build.sbt:

    // important to use ~= so that any other initializations aren't dropped
    // the _ discards the meaningless () value previously assigned to 'initialize'
    initialize ~= { _ =>
      System.setProperty( "config.file", "debug.conf" )
    }
    

    Related: When doing this to change the Typesafe Configuration that gets loaded (my use case), one needs to also manually include the default config. For this, the Typesafe Configuration's suggested include "application" wasn't enough but include classpath("application.conf") worked. Thought to mention since some others may well be wanting to override system properties for precisely the same reason.

    Source: discussion on the sbt mailing list

提交回复
热议问题