When running tasks (e.g., test
, jmh:run
), I often want to specify javaOptions
which are tedious to type by hand (e.g., to dump program data).
This is my current approach:
// build.sbt
lazy val myProject = project
...
.settings(
...
Test / javaOptions ++= if (sys.props.get("dump").nonEmpty) Seq("-X...", ...) else Nil
)
I can set system properties on sbt launch (e.g., sbt -Ddump
) and then check them with sys.props
, but changing these properties requires me to reload sbt. I would like to parse some arguments when the task is invoked, such that I can write test -dump
and modify the Test / javaOptions
setting accordingly.
Is this possible? Someone recommended I override the default task but I'm having trouble figuring out what that would look like. I have a suspicion I need an InputTask
for this, but also don't know what that'd look like.