From 38edf579007bbf554cfd45afe713727550ff3536 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Wed, 5 Jun 2024 10:17:23 -0700 Subject: [PATCH] Update Gradle config to always compile Java code using JDK 17 (#971) Before this change, if Gradle itself was running on JDK 21+, compilation would fail. --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 8a5760f562..dd787f61c6 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,14 @@ subprojects { project -> } project.tasks.withType(JavaCompile) { dependsOn(installGitHooks) + // Always compile using JDK 17, independent of the JDK version used to run Gradle. + // We can't compile on JDK 21 since some internal javac APIs changed between 17 + // and 21, and for now NullAway compiles against the JDK 17 APIs and uses reflection + // on JDK 21+. This configuration means compilation will succeed even if Gradle + // is running on JDK 21+. + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(17) + } options.compilerArgs += [ "-Xlint:deprecation", "-Xlint:rawtypes",