[GRADLE-2485] Setting test.jvmArgs accidentally sets test.debug=false Created: 18/Sep/12  Updated: 04/Jan/13  Resolved: 01/Nov/12

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.3-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Fixed Votes: 0


 Description   

I use jacoco for code coverage during testing which uses [a javaagent like so]([1]http://stevendick.github.com/blog/201...). 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
----------------------------------------------------------------------------------------
[1] http://stevendick.github.com/blog/2012/01/22/jacoco-and-gradle/



 Comments   
Comment by Gradle Forums [ 18/Sep/12 ]

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

Comment by Gradle Forums [ 18/Sep/12 ]

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.

Comment by Gradle Forums [ 18/Sep/12 ]

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?

Comment by Gradle Forums [ 18/Sep/12 ]

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.

Comment by Gradle Forums [ 18/Sep/12 ]

You are right, something looks wrong here. Probably the `else

{ debug = false }

` just has to go. Pull requests welcome (please include a test).

Comment by Gradle Forums [ 18/Sep/12 ]

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.

Comment by Matt Khan [ 06/Oct/12 ]

I have submitted a pull request (https://github.com/gradle/gradle/pull/103) with a fix for this

Generated at Wed Jun 30 12:23:14 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.