7

I'm trying to set jvmargs for unit tests using kotlin-dsl and I can't get it to work.

This is so that I can add the "-noverify" argument and allow intellji test runner to collect code coverage info.

Groovy, works:

testOptions {
        unitTests.all {
            jvmArgs '-noverify'
        }
    }

Kotlin, doesn't work:

testOptions {
        unitTests.all(KotlinClosure1<Any, Test>({
            (this as Test).also { jvmArgs("-noverify") }
        }, this))
    }

This too:

testOptions {
        unitTests.all(KotlinClosure1<Any, Test>({
            (this as Test).also { jvmArgs = listOf("-noverify") }
        }, this))
    }

Nothing seems to work, what am I missing?

2 Answers2

8

I was having the same issue. The following snippet works.

tasks.withType<Test>().all {
    jvmArgs("-noverify")
}

Ref - https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html#jvmArgs-java.lang.Object...-

Verified using Gradle-5.1.-all version

omni.present
  • 91
  • 1
  • 4
8

This question is a little old but wanted to post an updated Kotlin DSL version for 2021:

testOptions.unitTests.all { it.jvmArgs("-noverify") }
opt05
  • 813
  • 11
  • 21