How do I set a system property for my project in sbt?

后端 未结 3 2071
长发绾君心
长发绾君心 2021-02-14 06:35

I\'m sure I\'m missing something really simple... I want to set the system property java.awt.headless to true for my sbt project. Reading the page on p

3条回答
  •  难免孤独
    2021-02-14 07:00

    If you're trying to set SBT properties, like plugin settings, then the following worked for me with 0.13+. The following however did work, when trying to pass in Liquibase settings, like password, from our CI frameworks.

    In your build.sbt

    Ugly, but supplies defaults, and optionally grabs from System.properties. This way you've got your default and override cases covered.

    def sysPropOrDefault(propName:String,default:String):String = Option(System.getProperty(propName)).getOrElse(default)
    
    liquibaseUsername := sysPropOrDefault("liquibase.username","change_me")
    liquibasePassword := sysPropOrDefault("liquibase.password","chuck(\)orris")
    

    From the commandline

    Now just override via -Dprop=value like you would with Maven or other JVM programs. Note props appear before SBT task.

    sbt -Dliquibase.password="shh" -Dliquibase.username="bob" liquibase:liquibase-update

提交回复
热议问题