Skip to content

Commit fd32952

Browse files
Excavator: Enabling the new Gradle Toolchains & Daemon JDK Setup
1 parent e944e3e commit fd32952

37 files changed

+305
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ out/
3232

3333
# Log Files
3434
*/var/log/
35+
36+
# Gradle JDKs setup
37+
!gradle/*

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildscript {
99
classpath 'com.palantir.baseline:gradle-baseline-java:6.25.0'
1010
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.27.0'
1111
classpath 'com.palantir.gradle.gitversion:gradle-git-version:3.2.0'
12+
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.64.0'
1213
classpath 'com.palantir.javaformat:gradle-palantir-java-format:2.62.0'
1314
classpath 'com.palantir.suppressible-error-prone:gradle-suppressible-error-prone:2.9.0'
1415
classpath 'gradle.plugin.org.inferred:gradle-processors:3.7.0'
@@ -23,6 +24,7 @@ buildscript {
2324
apply plugin: 'com.palantir.failure-reports'
2425
apply plugin: 'com.palantir.baseline'
2526
apply plugin: 'com.palantir.git-version'
27+
apply plugin: 'com.palantir.jdks'
2628
apply plugin: 'com.palantir.consistent-versions'
2729
apply plugin: 'com.palantir.baseline-java-versions'
2830
apply plugin: 'com.palantir.jdks.latest'
@@ -55,3 +57,7 @@ javaVersions {
5557
libraryTarget = 21
5658
runtime = 21
5759
}
60+
61+
jdks {
62+
daemonTarget = 17
63+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ org.gradle.caching = true
22
org.gradle.parallel = true
33
org.gradle.jvmargs = --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
44
palantir.native.formatter=true
5+
palantir.jdk.setup.enabled=true

gradle/gradle-daemon-jdk-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17

gradle/gradle-jdks-functions.sh

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/bin/sh
2+
3+
set -e
4+
# Set pipefail if it works in a subshell, disregard if unsupported
5+
# shellcheck disable=SC3040
6+
if (set -o pipefail 2>/dev/null); then
7+
set -o pipefail
8+
fi
9+
#
10+
# (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
11+
#
12+
# Licensed under the Apache License, Version 2.0 (the "License");
13+
# you may not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing, software
19+
# distributed under the License is distributed on an "AS IS" BASIS,
20+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
# See the License for the specific language governing permissions and
22+
# limitations under the License.
23+
#
24+
25+
TMP_WORK_DIR=$(mktemp -d)
26+
export TMP_WORK_DIR
27+
28+
# writing to stderr
29+
write() { echo "$*" >&2; }
30+
31+
cleanup() {
32+
[ -d "$TMP_WORK_DIR" ] && rm -rf "$TMP_WORK_DIR"
33+
}
34+
35+
die() {
36+
write
37+
write "$*"
38+
write
39+
cleanup
40+
exit 1
41+
} >&2
42+
43+
read_value() {
44+
if [ ! -f "$1" ]; then
45+
die "ERROR: $1 not found, aborting Gradle JDK setup"
46+
fi
47+
read -r value < "$1" || die "ERROR: Unable to read value from $1. Make sure the file ends with a newline."
48+
echo "$value"
49+
}
50+
51+
get_os() {
52+
# OS specific support; same as gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentOs.java
53+
case "$( uname )" in #(
54+
Linux* ) os_name="linux" ;; #(
55+
Darwin* ) os_name="macos" ;; #(
56+
* ) die "ERROR Unsupported OS: $( uname )" ;;
57+
esac
58+
59+
if [ "$os_name" = "linux" ]; then
60+
ldd_output=$(ldd --version 2>&1 || true)
61+
if echo "$ldd_output" | grep -qi glibc; then
62+
os_name="linux-glibc"
63+
elif echo "$ldd_output" | grep -qi "gnu libc"; then
64+
os_name="linux-glibc"
65+
elif echo "$ldd_output" | grep -qi musl; then
66+
os_name="linux-musl"
67+
else
68+
die "Unable to determine glibc or musl based Linux distribution: ldd_output: $ldd_output"
69+
fi
70+
fi
71+
72+
echo "$os_name"
73+
}
74+
75+
get_arch() {
76+
# Arch specific support, see: gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentArch.java
77+
case "$(uname -m)" in #(
78+
x86_64* ) arch_name="x86-64" ;; #(
79+
x64* ) arch_name="x86-64" ;; #(
80+
amd64* ) arch_name="x86-64" ;; #(
81+
arm64* ) arch_name="aarch64" ;; #(
82+
arm* ) arch_name="aarch64" ;; #(
83+
aarch64* ) arch_name="aarch64" ;; #(
84+
x86* ) arch_name="x86" ;; #(
85+
i686* ) arch_name="x86" ;; #(
86+
* ) die "ERROR Unsupported architecture: $( uname -m )" ;;
87+
esac
88+
89+
echo "$arch_name"
90+
}
91+
92+
get_gradle_jdks_home() {
93+
gradle_user_home=${GRADLE_USER_HOME:-"$HOME"/.gradle}
94+
gradle_jdks_home="$gradle_user_home"/gradle-jdks
95+
echo "$gradle_jdks_home"
96+
}
97+
98+
get_java_home() {
99+
java_bin=$(find "$1" -type f -name "java" -path "*/bin/java" ! -type l -print -quit)
100+
echo "${java_bin%/*/*}"
101+
}
102+
103+
GRADLE_JDKS_HOME=$(get_gradle_jdks_home)
104+
mkdir -p "$GRADLE_JDKS_HOME"
105+
export GRADLE_JDKS_HOME
106+
107+
OS=$(get_os)
108+
export OS
109+
110+
ARCH=$(get_arch)
111+
export ARCH
112+
113+
install_and_setup_jdks() {
114+
gradle_dir=$1
115+
scripts_dir=${2:-"$1"}
116+
117+
for dir in "$gradle_dir"/jdks/*/; do
118+
major_version_dir=${dir%*/}
119+
major_version=${major_version_dir##*/}
120+
if [ "$major_version" = "8" ]; then
121+
write "Skipping JDK 8 installation as it is not supported by Gradle JDKs Setup."
122+
continue
123+
fi
124+
distribution_local_path=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/local-path)
125+
distribution_url=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/download-url)
126+
# Check if distribution exists in $GRADLE_JDKS_HOME
127+
jdk_installation_directory="$GRADLE_JDKS_HOME"/"$distribution_local_path"
128+
if [ ! -d "$jdk_installation_directory" ]; then
129+
write "JDK installation '$jdk_installation_directory' does not exist, installing '$distribution_url' in progress ..."
130+
elif [ ! -f "$jdk_installation_directory/bin/java" ]; then
131+
write "Java executable not found in $jdk_installation_directory/bin/java, re-installing the JDK...."
132+
else
133+
continue
134+
fi
135+
# Download and extract the distribution into a temporary directory
136+
in_progress_dir="$TMP_WORK_DIR/$distribution_local_path.in-progress"
137+
mkdir -p "$in_progress_dir"
138+
cd "$in_progress_dir" || die "failed to change dir to $in_progress_dir"
139+
if command -v curl > /dev/null 2>&1; then
140+
write "Using curl to download $distribution_url"
141+
case "$distribution_url" in
142+
*.zip)
143+
distribution_name=${distribution_url##*/}
144+
curl -L -C - "$distribution_url" -o "$distribution_name"
145+
tar -xzf "$distribution_name"
146+
;;
147+
*)
148+
curl -L -C - "$distribution_url" | tar -xzf -
149+
;;
150+
esac
151+
elif command -v wget > /dev/null 2>&1; then
152+
write "Using wget to download $distribution_url"
153+
case "$distribution_url" in
154+
*.zip)
155+
distribution_name=${distribution_url##*/}
156+
wget -c "$distribution_url" -O "$distribution_name"
157+
tar -xzf "$distribution_name"
158+
;;
159+
*)
160+
wget -qO- -c "$distribution_url" | tar -xzf -
161+
;;
162+
esac
163+
else
164+
die "ERROR: Neither curl nor wget are installed, Could not set up JAVA_HOME"
165+
fi
166+
cd - > /dev/null || die "failed to change dir to old pwd: $OLDPWD"
167+
168+
# Finding the java_home
169+
java_home=$(get_java_home "$in_progress_dir")
170+
"$java_home"/bin/java -cp "$scripts_dir"/gradle-jdks-setup.jar com.palantir.gradle.jdks.setup.GradleJdkInstallationSetup jdkSetup "$jdk_installation_directory" || die "Failed to set up JDK $jdk_installation_directory"
171+
write "Successfully installed JDK distribution in $jdk_installation_directory"
172+
done
173+
}

gradle/gradle-jdks-setup.jar

111 KB
Binary file not shown.

gradle/gradle-jdks-setup.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/sh
2+
#
3+
# (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
##############################################################################
19+
#
20+
# Gradle jdk set up script for POSIX generated by gradle-jdks.
21+
#
22+
# This script does the following:
23+
# (1) Downloads all the JDK distributions that are present in `gradle/jdks`
24+
# (2) Installs the distributions in a temporary directory
25+
# (3) Calls the java class `GradleJdkInstallationSetup` that will move each distribution to
26+
# `$GRADLE_USER_HOME/${local_path}` based on the local_path=`gradle/jdks/${majorVersion}/${os}/${arch}/local_path`
27+
# and it will set up the certificates based on `gradle/certs` entries for the locally installed distribution
28+
# (4) Sets `org.gradle.java.home` to the JDK distribution that is used by the Gradle Daemon
29+
#
30+
#
31+
# Important for running:
32+
# This script requires all of these POSIX shell features:
33+
# * functions;
34+
# * expansions «$var», «${var}», «${var%suffix}», and «$( cmd )»;
35+
# * compound commands having a testable exit status, especially «case»;
36+
# * various built-in commands including «command» and «set».
37+
#
38+
##############################################################################
39+
40+
set -e
41+
# Set pipefail if it works in a subshell, disregard if unsupported
42+
# shellcheck disable=SC3040
43+
if (set -o pipefail 2>/dev/null); then
44+
set -o pipefail
45+
fi
46+
47+
# Resolve links: $0 may be a link
48+
app_path=$0
49+
50+
# Need this for daisy-chained symlinks.
51+
while
52+
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
53+
[ -h "$app_path" ]
54+
do
55+
ls=$( ls -ld "$app_path" )
56+
link=${ls#*' -> '}
57+
case $link in #(
58+
/*) app_path=$link ;; #(
59+
*) app_path=$APP_HOME$link ;;
60+
esac
61+
done
62+
63+
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
64+
APP_HOME=${APP_HOME%/gradle}
65+
APP_GRADLE_DIR="$APP_HOME"/gradle
66+
67+
# Loading gradle jdk functions
68+
. "$APP_GRADLE_DIR"/gradle-jdks-functions.sh
69+
70+
install_and_setup_jdks "$APP_GRADLE_DIR"
71+
72+
gradle_daemon_jdk_version=$(read_value "$APP_GRADLE_DIR"/gradle-daemon-jdk-version)
73+
gradle_daemon_jdk_distribution_local_path=$(read_value "$APP_GRADLE_DIR"/jdks/"$gradle_daemon_jdk_version"/"$OS"/"$ARCH"/local-path)
74+
"$GRADLE_JDKS_HOME"/"$gradle_daemon_jdk_distribution_local_path"/bin/java -cp "$APP_GRADLE_DIR"/gradle-jdks-setup.jar com.palantir.gradle.jdks.setup.GradleJdkInstallationSetup daemonSetup "$APP_HOME" "$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path"
75+
76+
# [Used by ./gradlew only] Setting the Gradle Daemon Java Home to the JDK distribution
77+
export GRADLE_DAEMON_JDK="$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path"
78+
set -- "-Dorg.gradle.java.home=$GRADLE_DAEMON_JDK" "$@"
79+
80+
cleanup
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-linux-aarch64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1-glibc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-linux-x64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1-glibc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-alpine-linux-aarch64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1-musl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-alpine-linux-x64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1-musl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-macosx-aarch64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-macosx-x64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/17.0.12.7.1/amazon-corretto-17.0.12.7.1-windows-x64-jdk.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-17.0.12.7.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/21.0.4.7.1/amazon-corretto-21.0.4.7.1-linux-aarch64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-21.0.4.7.1-glibc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/21.0.4.7.1/amazon-corretto-21.0.4.7.1-linux-x64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-21.0.4.7.1-glibc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/21.0.4.7.1/amazon-corretto-21.0.4.7.1-alpine-linux-aarch64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-21.0.4.7.1-musl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/21.0.4.7.1/amazon-corretto-21.0.4.7.1-alpine-linux-x64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-21.0.4.7.1-musl
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/21.0.4.7.1/amazon-corretto-21.0.4.7.1-macosx-aarch64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-21.0.4.7.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/21.0.4.7.1/amazon-corretto-21.0.4.7.1-macosx-x64.tar.gz
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-21.0.4.7.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/21.0.4.7.1/amazon-corretto-21.0.4.7.1-windows-x64-jdk.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
amazon-corretto-21.0.4.7.1

gradlew

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@
6161
# You can find Gradle at https://github.com/gradle/gradle/.
6262
#
6363
##############################################################################
64+
# >>> Gradle JDK setup >>>
65+
# !! Contents within this block are managed by 'palantir/gradle-jdks' !!
66+
if [ -f gradle/gradle-jdks-setup.sh ]; then
67+
if ! . gradle/gradle-jdks-setup.sh; then
68+
echo "Failed to set up JDK, running gradle/gradle-jdks-setup.sh failed with non-zero exit code" >&2
69+
exit 1
70+
fi
71+
# Setting JAVA_HOME to the gradle daemon to make sure gradlew uses this jdk for `JAVACMD`
72+
JAVA_HOME="$GRADLE_DAEMON_JDK"
73+
fi
74+
# <<< Gradle JDK setup <<<
6475

6576
# Attempt to set APP_HOME
6677

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ pluginManagement {
55
}
66

77
buildscript {
8+
dependencies { classpath 'com.palantir.gradle.jdks:gradle-jdks-settings:0.64.0' }
89
repositories {
910
mavenCentral()
1011
}
1112
}
13+
apply plugin: 'com.palantir.jdks.settings'
1214

1315
rootProject.name = 'java-compute-module'
1416

0 commit comments

Comments
 (0)