onkami
onkami

Reputation: 9411

Increase heap memory for 'gradle test'

I have a problem running 'gradle test' against my Spring Boot application as I see signs of GC called too many times and my tests fail likely due to delays caused by agressive GC work.

How I can tell gradle to use more heap memory allowed for JVM during test phase, or in general?

Upvotes: 76

Views: 41346

Answers (2)

Benedikt Köppel
Benedikt Köppel

Reputation: 5109

If you want to configure the memory for Gradle, you can configure in gradle.properties:

org.gradle.jvmargs=-Xmx2G -Xms1G

More details:

Note that this does not set the memory for the tests. To set memory for the tests, follow miskender's answer.

Upvotes: 0

miskender
miskender

Reputation: 7948

You can use the maxHeapSize configuration of the Test task.

Example in Gradle/Groovy:

test {
  minHeapSize = "128m" // initial heap size
  maxHeapSize = "512m" // maximum heap size
  jvmArgs '-XX:MaxPermSize=256m' // mem argument for the test JVM
}

Or the same in Kotlin:

withType<Test> {
  minHeapSize = "512m"
  maxHeapSize = "1024m"
  jvmArgs = listOf("-XX:MaxPermSize=512m")
}

Check out the official docs for additional info.

Upvotes: 118

Related Questions