Nogurenn
Nogurenn

Reputation: 878

SBT system property not being set

I'm trying to do sbt flywayMigrate -Denvi=foo but the system property envi is not being set. Pointers for debugging is greatly appreciated as I haven't been successful in identifying the cause of this issue for hours now. No question in SO or anywhere else have had this issue so far.

In build.sbt, this will be used as a variable.

lazy val envi = sys.props.getOrElse("envi", "default")

Using sys.env.get("ENVI") instead is currently not an option due to shared/team repo considerations.

sbt console -Denvi=foo
scala> sys.props.get("envi")
res0: Option[String] = None
scala> sys.props.getOrElse("envi", "default")
res1: Option[String] = default

scala, sbt installed using brew

Upvotes: 1

Views: 732

Answers (1)

Harald Gliebe
Harald Gliebe

Reputation: 7564

You have to put the environment variable before the command:

sbt -Denvi=foo console

otherwise it will be passed as an argument to the main class instead of to the JVM.

Alternatively you can set the environment in the JAVA_OPTS variable before starting sbt:

export JAVA_OPTS="-Denvi=foo"
sbt console
scala> sys.props.getOrElse("envi", "default")
res0: String = foo

Upvotes: 1

Related Questions