Skip to content

Commit 7d11d0d

Browse files
Excavator: Enabling the new Gradle Toolchains & Daemon JDK Setup (#719)
1 parent b311b4b commit 7d11d0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+322
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ reports/
3838
*.tmproj
3939
*.tmproject
4040
*.sw[op]
41+
42+
# Gradle JDKs setup
43+
!gradle/*

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ buildscript {
2323

2424
dependencies {
2525
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0'
26-
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.37.0'
26+
classpath 'com.palantir.gradle.jdks:gradle-jdks:0.47.0'
2727
classpath 'com.palantir.gradle.jdkslatest:gradle-jdks-latest:0.13.0'
2828
classpath 'com.gradle.publish:plugin-publish-plugin:1.3.0'
2929
classpath 'com.palantir.baseline:gradle-baseline-java:5.61.0'
@@ -51,6 +51,7 @@ apply plugin: 'com.palantir.external-publish-jar'
5151
apply plugin: 'com.palantir.failure-reports'
5252
apply plugin: 'com.palantir.git-version'
5353
apply plugin: 'com.palantir.java-format'
54+
apply plugin: 'com.palantir.jdks'
5455
apply plugin: 'com.palantir.jdks.latest'
5556
apply plugin: 'org.inferred.processors'
5657

@@ -101,3 +102,7 @@ javaVersions {
101102
libraryTarget = 11
102103
runtime = 17
103104
}
105+
106+
jdks {
107+
daemonTarget = 17
108+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAME
66

77
org.gradle.caching=true
88
org.gradle.parallel=true
9+
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: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
cleanup() {
29+
[ -d "$TMP_WORK_DIR" ] && rm -rf "$TMP_WORK_DIR"
30+
}
31+
32+
die() {
33+
echo
34+
echo "$*"
35+
echo
36+
cleanup
37+
exit 1
38+
} >&2
39+
40+
read_value() {
41+
if [ ! -f "$1" ]; then
42+
die "ERROR: $1 not found, aborting Gradle JDK setup"
43+
fi
44+
read -r value < "$1" || die "ERROR: Unable to read value from $1. Make sure the file ends with a newline."
45+
echo "$value"
46+
}
47+
48+
get_os() {
49+
# OS specific support; same as gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentOs.java
50+
case "$( uname )" in #(
51+
Linux* ) os_name="linux" ;; #(
52+
Darwin* ) os_name="macos" ;; #(
53+
* ) die "ERROR Unsupported OS: $( uname )" ;;
54+
esac
55+
56+
if [ "$os_name" = "linux" ]; then
57+
ldd_output=$(ldd --version 2>&1 || true)
58+
if echo "$ldd_output" | grep -qi glibc; then
59+
os_name="linux-glibc"
60+
elif echo "$ldd_output" | grep -qi "gnu libc"; then
61+
os_name="linux-glibc"
62+
elif echo "$ldd_output" | grep -qi musl; then
63+
os_name="linux-musl"
64+
else
65+
die "Unable to determine glibc or musl based Linux distribution: ldd_output: $ldd_output"
66+
fi
67+
fi
68+
69+
echo "$os_name"
70+
}
71+
72+
get_arch() {
73+
# Arch specific support, see: gradle-jdks:com.palantir.gradle.jdks.setup.common.CurrentArch.java
74+
case "$(uname -m)" in #(
75+
x86_64* ) arch_name="x86-64" ;; #(
76+
x64* ) arch_name="x86-64" ;; #(
77+
amd64* ) arch_name="x86-64" ;; #(
78+
arm64* ) arch_name="aarch64" ;; #(
79+
arm* ) arch_name="aarch64" ;; #(
80+
aarch64* ) arch_name="aarch64" ;; #(
81+
x86* ) arch_name="x86" ;; #(
82+
i686* ) arch_name="x86" ;; #(
83+
* ) die "ERROR Unsupported architecture: $( uname -m )" ;;
84+
esac
85+
86+
echo "$arch_name"
87+
}
88+
89+
get_gradle_jdks_home() {
90+
gradle_user_home=${GRADLE_USER_HOME:-"$HOME"/.gradle}
91+
gradle_jdks_home="$gradle_user_home"/gradle-jdks
92+
echo "$gradle_jdks_home"
93+
}
94+
95+
get_java_home() {
96+
java_bin=$(find "$1" -type f -name "java" -path "*/bin/java" ! -type l -print -quit)
97+
echo "${java_bin%/*/*}"
98+
}
99+
100+
GRADLE_JDKS_HOME=$(get_gradle_jdks_home)
101+
mkdir -p "$GRADLE_JDKS_HOME"
102+
export GRADLE_JDKS_HOME
103+
104+
OS=$(get_os)
105+
export OS
106+
107+
ARCH=$(get_arch)
108+
export ARCH
109+
110+
install_and_setup_jdks() {
111+
gradle_dir=$1
112+
scripts_dir=${2:-"$1"}
113+
114+
for dir in "$gradle_dir"/jdks/*/; do
115+
major_version_dir=${dir%*/}
116+
major_version=${major_version_dir##*/}
117+
if [ "$major_version" = "8" ]; then
118+
echo "Skipping JDK 8 installation as it is not supported by Gradle JDKs Setup."
119+
continue
120+
fi
121+
distribution_local_path=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/local-path)
122+
distribution_url=$(read_value "$major_version_dir"/"$OS"/"$ARCH"/download-url)
123+
# Check if distribution exists in $GRADLE_JDKS_HOME
124+
jdk_installation_directory="$GRADLE_JDKS_HOME"/"$distribution_local_path"
125+
if [ ! -d "$jdk_installation_directory" ]; then
126+
# Download and extract the distribution into a temporary directory
127+
echo "JDK installation '$jdk_installation_directory' does not exist, installing '$distribution_url' in progress ..."
128+
in_progress_dir="$TMP_WORK_DIR/$distribution_local_path.in-progress"
129+
mkdir -p "$in_progress_dir"
130+
cd "$in_progress_dir" || die "failed to change dir to $in_progress_dir"
131+
if command -v curl > /dev/null 2>&1; then
132+
echo "Using curl to download $distribution_url"
133+
case "$distribution_url" in
134+
*.zip)
135+
distribution_name=${distribution_url##*/}
136+
curl -C - "$distribution_url" -o "$distribution_name"
137+
tar -xzf "$distribution_name"
138+
;;
139+
*)
140+
curl -C - "$distribution_url" | tar -xzf -
141+
;;
142+
esac
143+
elif command -v wget > /dev/null 2>&1; then
144+
echo "Using wget to download $distribution_url"
145+
case "$distribution_url" in
146+
*.zip)
147+
distribution_name=${distribution_url##*/}
148+
wget -c "$distribution_url" -O "$distribution_name"
149+
tar -xzf "$distribution_name"
150+
;;
151+
*)
152+
wget -qO- -c "$distribution_url" | tar -xzf -
153+
;;
154+
esac
155+
else
156+
die "ERROR: Neither curl nor wget are installed, Could not set up JAVA_HOME"
157+
fi
158+
cd - || exit
159+
160+
# Finding the java_home
161+
java_home=$(get_java_home "$in_progress_dir")
162+
"$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"
163+
echo "Successfully installed JDK distribution in $jdk_installation_directory"
164+
fi
165+
done
166+
}

gradle/gradle-jdks-setup.jar

109 KB
Binary file not shown.

gradle/gradle-jdks-setup.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
set -- "-Dorg.gradle.java.home=$GRADLE_JDKS_HOME/$gradle_daemon_jdk_distribution_local_path" "$@"
78+
79+
cleanup
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://corretto.aws/downloads/resources/11.0.22.7.1/amazon-corretto-11.0.22.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-11.0.22.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/11.0.22.7.1/amazon-corretto-11.0.22.7.1-linux-x64.tar.gz

0 commit comments

Comments
 (0)