How do I define "run" and "test:run" tasks to run with hprof on forked JVM.
in build.sbt
fork in run := true
javaOptions in run += "-agentlib:hprof"
This setting makes both run tasks work with hprof.
I want to define my hprof task for keeping default "run" and "test:run" tasks and use from sbt prompt.
//define myHprofTask, alias de开发者_Go百科fault run task
fork in myHprofTask := true
javaOptions in myHprofTask += "-agentlib:hprof"
How can I define tasks like this?
This is based on the Additional run tasks
section of https://github.com/harrah/xsbt/wiki/Common-Tasks.
Define the new task key:
lazy val myHprofTask = TaskKey[Unit]("my-hprof-task")
Add a new run task in the
Compile
configuration (themyHprofTask in Compile
part) using theCompile
classpath that executesdemo.Main
, passing "arg1" and "arg2" as arguments:fullRunTask(myHprofTask in Compile, Compile, "demo.Main", "arg1", "arg2")
Do the same for the
Test
configuration:fullRunTask(myHprofTask in Test, Test, "demo.TestMain", "arg1", "arg2")
Then, you can define the
fork
andjavaOptions
settings as in the question.
Here is the full example using the quick configuration style (build.sbt
):
{
lazy val myHprofTask = TaskKey[Unit]("my-hprof-task")
seq(
fullRunTask(myHprofTask in Compile, Compile, "demo.Main", "arg1"),
fullRunTask(myHprofTask in Test, Test, "demo.TestMain", "arg1"),
fork in myHprofTask := true,
javaOptions in myHprofTask += "-agentlib:hprof"
)
}
精彩评论