[13.1] Conditionally disable fork in Test if running -jvm-debug

139 views
Skip to first unread message

ed eustace

unread,
Feb 12, 2014, 8:37:44 AM2/12/14
to simple-b...@googlegroups.com
Hi,
Is there a way to conditionally disable forking if the project is run in debug mode:

sbt -jvm-debug 9999

Then in my build: 

fork in Test := { 
    //find a key that lets me know if debugging in set up
    !isDebugging.value
}

Ed

Konrad Malawski

unread,
Feb 12, 2014, 9:38:55 AM2/12/14
to simple-b...@googlegroups.com

Hi Ed!
This can be addressed by using a built-in Java MX bean:

val debugInUse = SettingKey[Boolean]("debug-in-use", "debug is used”)
debugInUse := {
  val jvmOpts = java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments
  println("jvmOpts = " + jvmOpts)
  jvmOpts contains "-Xdebug"
}

Output:

jvmOpts = [-Dfile.encoding=UTF8, -Xms512m, ..., -Xdebug, -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005]
> debug-in-use
[info] true

I didn’t see a setting key in sbt itself that would expose this list, javaOptions available are for forked jvms, which brings me to the idea:
you could explore passing through the debug options (if present) to the javaOptions for the forked jvms (on another port then).

more info on this here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Forking.html#forked-jvm-options

Not sure what better suits your use-case. I hope this helps :-)

-- 
Konrad

Reply all
Reply to author
Forward
0 new messages