开发者

How to define tasks to run with hprof from sbt 0.10

开发者 https://www.devze.com 2023-03-25 05:39 出处:网络
How do I define \"run\" and \"test:run\" tasks to run with hprof on forked JVM. in build.sbt fork in run := true

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.

  1. Define the new task key:

    lazy val myHprofTask = TaskKey[Unit]("my-hprof-task")
    
  2. Add a new run task in the Compile configuration (the myHprofTask in Compile part) using the Compile classpath that executes demo.Main, passing "arg1" and "arg2" as arguments:

    fullRunTask(myHprofTask in Compile, Compile, "demo.Main", "arg1", "arg2")
    
  3. Do the same for the Test configuration:

    fullRunTask(myHprofTask in Test, Test, "demo.TestMain", "arg1", "arg2")
    
  4. Then, you can define the fork and javaOptions 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"
  )
}
0

精彩评论

暂无评论...
验证码 换一张
取 消