From 0112b3ae0656b58c9d11987356bec7ef0b85114e Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Thu, 25 Jan 2024 12:08:30 -0500 Subject: [PATCH] Make the formatting tasks work with Java 17 (take 2) (#2305) We should not assume org.gradle.java.home to exist on kokoro or GCB. --- build.gradle | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index ce4a8c0e9..0af7084f9 100644 --- a/build.gradle +++ b/build.gradle @@ -504,7 +504,13 @@ def createGetBuildSrcDirectDepsTask(outputFileName) { rootProject.ext { invokeJavaDiffFormatScript = { action -> def javaHome = project.findProperty('org.gradle.java.home') - println("Running the formatting tool with JDK at $javaHome") + def javaBin + if (javaHome != null) { + javaBin = "$javaHome/bin/java" + } else { + javaBin = ext.execInBash("which java", rootDir) + } + println("Running the formatting tool with $javaBin") def scriptDir = rootDir.path.endsWith('buildSrc') ? "${rootDir}/../java-format" : "${rootDir}/java-format" @@ -515,7 +521,7 @@ rootProject.ext { def pythonExe = getPythonExecutable() return ext.execInBash( - "JAVA=${javaHome}/bin/java PYTHON=${pythonExe} ${formatDiffScript} ${action}", "${workingDir}") + "JAVA=${javaBin} PYTHON=${pythonExe} ${formatDiffScript} ${action}", "${workingDir}") } }