I want to tweak JVM parameters for testing - is th...
# gradle
k
I want to tweak JVM parameters for testing - is there a difference between
tasks { test { jvmArgs = ...}}
vs.
tasks { withType<Test> { jvmArgs = ...}
? It seems to work identically, but is one way better than the other?
f
The first invocation is lazy (it uses
named
underneath) and afaik the second is eager. Another difference is that the first only sets the JVM arguments for the
:test
task whereas the second sets it for every task that extends the
Test
task class (e.g. if you have
:test
and
:testIntegration
).
👍 1
v
Whether it is lazy or not depends on whether this is Groovy DSL or Kotlin DSL. But I think the second version and the server here hint at Kotlin. The second version could be made lazy using
withType<Test>().configureEach { ... }
instead. Then the remaining difference is configuring all tasks of type
Test
vs. only the
test
task as Richard said.
👍 1
j
Also it might not be possible to use the first version if you're configuring subprojects from the root build file for instance, for which the
test
task might not be available as a DSL accessor like this.
v
Which is bad practice anyway though. 🙂