How to specify JVM to gradle when using AWS lambda

Tags: ,



I’m using AWS Lambda with Java and I’m running into this issue. Can someone help?

“gradlew is using a JVM with major version 14 which is newer than 11 that is supported by AWS Lambda. The compiled function code may not run in AWS Lambda unless the project has been configured to be compatible with Java 11 using ‘targetCompatibility’ in Gradle”

I tried changing my JDK to https://aws.amazon.com/corretto/

And I tried following the instructions here but it was no help: https://www.jetbrains.com/help/idea/gradle-jvm-selection.html

Answer

Adding the following to your build.gradle should resolve this:

plugins {
    id("java-library") // or id("application")
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}


Source: stackoverflow