From b6a8ccd2bc5e994a4857c14f2c18e32c6c5744ff Mon Sep 17 00:00:00 2001 From: Bernardo Gomez Palacio Date: Wed, 29 Jun 2022 11:09:45 -0700 Subject: [PATCH] Adopt Gradle Toolchain for the JDK Adopting the Gradle Toolchain for the JDK will make the build _safer_ in machines that have multiple JDKs installed and that by mistake can build the project using a JDK higher than the intended. As defined in [Gradle's docs](https://docs.gradle.org/current/userguide/toolchains.html), the toolchains will give us... > Executing the build (e.g. using gradle check) will now handle several things for you and others running your build > Setup all compile, test and javadoc tasks to use the defined toolchain which may be different than the one Gradle itself uses > Gradle detects locally installed JVMs > Gradle chooses a JRE/JDK matching the requirements of the build (in this case a JVM supporting Java 8) > If no matching JVM is found, it will automatically download a matching JDK from AdoptOpenJDK --- build.gradle | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 2a0aa1eb97..8048a460af 100644 --- a/build.gradle +++ b/build.gradle @@ -175,8 +175,12 @@ subprojects { apply from: "${rootDir}/gradle/javadoc.gradle" apply from: "${rootDir}/gradle/errorprone.gradle" - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + + java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + } + } jacoco { toolVersion = '0.8.7' @@ -213,16 +217,6 @@ subprojects { "-Xlint:rawtypes" ] - compileJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - } - - compileTestJava { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - } - if (JavaVersion.current().isJava8Compatible()) { compileTestJava.options.compilerArgs += "-parameters" tasks.withType(Javadoc) {