0

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.

MattDs17
  • 401
  • 1
  • 4
  • 20

1 Answers1

0

You don’t need to reload sbt, if you are running sbt in a shell, you will need to programtically call‚ sys.props.set

Derrops
  • 7,651
  • 5
  • 30
  • 60