I fixed this problem by changing the Gradle JVM settings in IntelliJ settings:
- In the Settings/Preferences dialog, go to Build, Execution, Deployment | Build Tools | Gradle.
- Under the Gradle section, change the Gradle JVM option. Select a Gradle JVM which works for you.
See https://www.jetbrains.com/help/idea/gradle-jvm-selection.html#jvm_settings