Borrowing from this helpful answer, I tried to pass -Dfoo=bar
to sbt console
.
Given an SBT project having only a build.sbt
:
$cat build.sbt
scalaVersion := "2.11.8"
fork := true
I attempted:
$sbt '; set javaOptions += "-Dfoo=bar" ; console'
scala> sys.props.get("foo")
res0: Option[String] = None
but, I had expected Some("bar")
rather than None
given the set ...
argument.
However, using sbt ... run
worked as expected:
$cat src/main/scala/net/Main.scala
package net
object Main {
def main(args: Array[String]): Unit =
println("sys.props.get('foo'): " + sys.props.get("foo"))
}
$sbt '; set javaOptions += "-Dfoo=bar" ; run'
[info] Running net.Main
[info] sys.props.get('foo'): Some(bar)
How can I pass foo=bar
as a System Property to the console
?