SBT: How to pass JVM and application command-line arguments to sbt

As a brief example today, here’s an example of how to pass both JVM command-line arguments and application command-line arguments to sbt, when running sbt from your operating system command line:

sbt -v -J-Xmx2048m -Duser.timezone=America/Denver "run Charles Carmichael"

When you do this as shown with sbt’s -v (verbose) option, you’ll see output like this:

[process_args] java_version = '11'
# Executing command line:
java
-Dfile.encoding=UTF-8
-Xmx2048m
-Duser.timezone=America/Denver
-jar
/Users/al/bin/sbt/bin/sbt-launch.jar
"run Charles Carmichael"

[info] running hello.Hello Charles Carmichael

That output verifies that the two JVM arguments are being properly passed into sbt. While you can’t tell it from this example (since I don’t share the code for my Scala application), the last line of output also verifies that my application command-line arguments have also made it to my application via sbt’s run option.