Setting test.jvmArgs accidentally sets test.debug=false

I use jacoco for code coverage during testing which uses a javaagent like so. This doesn’t play nice with the test.debug feature as the logic in JvmOptions#jvmArgs is based on processing the full set of options each time.

It seems there should be a way to add a jvm arg rather than overwrite them all each time. Does such a method exist?

Cheers Matt

Are you saying that ‘Test.jvmArgs()’ is overwriting arguments rather than adding them? I’d be very surprised if this was the case.

I misread the code, it affects the debug property only which is set to false every time you call jvmargs and don’t pass the 2 debug props. This suggests it is just a more specific bug than originally described.

You may still be misreading the code. It’s post-processing all JVM arguments, not just the ones passed in the current call. Is this causing any problems for you?

I don’t think I am, flow appears to be

  • evaluate args passed in for special treatment (enable assertions etc) - if no match, add to extraJvmArgs - search extraJvmArgs for debug switches - if both found, set debug to true and remove those switches from extraJvmArgs

now you call jvmArgs again, there will be nothing in extraJvmArgs and it will set debug to false as a result

you can prove this by adding some args to a test task and running with -Dtest.debug, it will print a statement to log to say it has set debug to true but it won’t fork the test into debug mode. As a result I have to reinstate debug prop after setting jvmargs.

You are right, something looks wrong here. Probably the ‘else { debug = false }’ just has to go. Pull requests welcome (please include a test).

This reproduces the problem:

apply plugin: "java"
  repositories {
  mavenCentral()
}
  dependencies {
  testCompile "junit:junit:4.10"
}
  test {
  debug = true
  jvmArgs "-Xmx256m"
}

Debug mode isn’t activated due to ‘jvmArgs’ being set after ‘debug’ in the build script. ‘-Dtest.debug’ doesn’t have this problem.