According to the documentation, an sbt forked process should receive the jvm settings of the current process:
By default, a forked process uses the same Java and Scala versions being used for the build and the working directory and JVM options of the current process. See: http://www.scala-sbt.org/0.13/docs/Forking.html
However that does not seem to be the case for me. Take the following test:
object Test {
def main(args: Array[String]): Unit = {
println("Conf: " + System.getProperty("config.resource"))
}
}
If I run this with sbt -Dconfig.resource=test.conf then "Conf: test.conf" gets printed. But once I add fork in run := true in my build.scala "Conf: null" is printed out. Which implies to me that the jvm options are not in fact getting passed to the forked process. Can someone tell me what am I missing here?
import sbt._
import Keys._
object Build extends Build {
lazy val root = (project in file(".")).
settings(
fork in run := true
)
}
This is what I used. It's an updated version of josephpconley
's answer.
javaOptions ++= {
val props = sys.props.toList
props.map {
case (key, value) => s"-D$key=$value"
}
},
The SBT documentation is correct, the JVM properties do get passed to the forked process. You're concerned about the System properties, however, which need to be passed manually. Try this to pass all system properties:
import scala.collection.JavaConversions._
javaOptions in run += {
val props = System.getProperties
props.stringPropertyNames().toList.map { configKey =>
s"-D$configKey=${props.getProperty(configKey)}"
}.mkString(" ")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With