OutOfMemory when using GradleRunner with multiple versions in test

I’m testing my plugin against multiple versions in a unit test. Therefor i use the GradleRunner

    GradleRunner.create()
            .withDebug(true)
            .withProjectDir(projectDir)
            .withPluginClasspath()
            .forwardOutput()
            .withGradleVersion(version)
            .build()

version is a parameter of my parameterized test

after some versions have been tested i’m running in an OutOfMemoryError (see Update Gradle Wrapper from 8.8 to 8.9. · gradle-dependency-analyze/gradle-dependency-analyze@c0aa42a (github.com)

i already tried to create for each test inside the project a gradle.properties file with the content

    props.setProperty("org.gradle.daemon", "false")
    props.setProperty("org.gradle.vfs.watch", "false")

to not spawn daemons and also disable file system watching

when attaching jconsole i see for each tested version threads still running after the version was tested

how to properly shut down the GradleRunner in my test so that i do not run in the OOM situation.

Increasing xmx i would like to avoid as this does not solve the underlaying problem

Trying to disable the daemon is pointless, as you are not using the daemon.

By using withDebug(true) you run the build in-process in the test worker process, so that by debugging the test process you right away also debug the build logic and do not need to separately attach the debugger to the daemon.

If you remove withDebug(true) or guard it, so that it is only done when you are actually debugging, you probably solve your problem and also have a more realistic test setting.
I do it like

if (runtimeMXBean.inputArguments.any { it.startsWith('-agentlib:jdwp=') }) {
    runner.withDebug(true)
}

Thx, this solved it. Totally overlooked the debug thingy still enabled.

1 Like