This issue seems to be related to Linux rather than Gradle as stated in the Jenkins docs:
In cases where virtual memory is running short the kernel OOM (Out of
Memory) killer may forcibly kill Jenkins or individual builds. If this
occurs on Linux you may see builds terminate with exit code 137 (128 +
signal number for SIGKILL). Thedmesg
command output will show log
messages that will confirm the action that the kernel took.
https://wiki.jenkins-ci.org/display/JENKINS/I’m+getting+OutOfMemoryError