While testing a large Gradle Java project, you may encounter an error such as:
Exception in thread "Daemon periodic checks" java.lang.OutOfMemoryError: Java heap space
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':snykResolvedDepsJson'.
> Java heap space
or:
>>> command: '/Users/<users>/Documents/Snyk/<project>/gradlew' snykResolvedDepsJson -q --build-file build.gradle --no-daemon -Dorg.gradle.parallel= -PonlySubProject=. -I /var/folders/s1/pshxvh0137q0r4rcwqzcvpqc0000gn/T/tmp-934asMoylf6Qdkh-init.gradle
>>> exit code: 1
>>> stderr:
java.lang.OutOfMemoryError: GC overhead limit exceeded
This is generally caused by a very large Gradle project that does not have sufficient heap space allocated to the project.
You can specify Gradle arguments inline with the Snyk command. For example:
$ GRADLE_OPTS="-Xmx4g" snyk test -d
This command will tell Gradle to use 4gb of Heap space, you can also try:
$ GRADLE_OPTS="-Xmx512m" snyk test -d
This command will tell Gradle to use 512mb of Heap space.
Other considerations:
We also always recommend making sure that you're on the latest version of Snyk to ensure that you're taking advantage of our latest fixes:
$ npm i -g snyk