Skip to content

Commit 5c39b3a

Browse files
authored
Improve openjdk::install_openjdk_via_jvm_common_buildpack (#181)
1 parent cc712ee commit 5c39b3a

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
* Improve OpenJDK installation via jvm-common buildpack to prevent function overrides and fix environment variable handling ([#181](https://github.com/heroku/heroku-buildpack-gradle/pull/181))
912

1013
## [v48] - 2025-09-17
1114

lib/openjdk.sh

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
set -euo pipefail
66

77
function openjdk::install_openjdk_via_jvm_common_buildpack() {
8-
local build_directory="${1}"
8+
local build_dir="${1}"
99
# The install_openjdk function from the JVM common buildpack requires the path to the host buildpack to write to the
1010
# export script so that OpenJDK can be found by subsequent buildpacks.
11-
local host_buildpack_directory="${2}"
11+
local host_buildpack_dir="${2}"
1212

1313
# Legacy behaviour for customers and testing code can override the download location of the heroku/jvm buildpack
1414
# with JVM_COMMON_BUILDPACK for testing and debugging purposes.
@@ -17,22 +17,42 @@ function openjdk::install_openjdk_via_jvm_common_buildpack() {
1717
local jvm_common_buildpack_tarball_path
1818
jvm_common_buildpack_tarball_path=$(mktemp)
1919

20-
local jvm_common_buildpack_directory
21-
jvm_common_buildpack_directory=$(mktemp -d)
20+
local jvm_common_buildpack_dir
21+
jvm_common_buildpack_dir=$(mktemp -d)
2222

23-
curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 5 --location "${jvm_common_buildpack_tarball_url}" -o "${jvm_common_buildpack_tarball_path}"
24-
tar -xzm --directory "${jvm_common_buildpack_directory}" --strip-components=1 -f "${jvm_common_buildpack_tarball_path}"
23+
curl \
24+
--connect-timeout 3 \
25+
--max-time 60 \
26+
--retry 5 \
27+
--retry-connrefused \
28+
--no-progress-meter \
29+
--fail \
30+
--location \
31+
"${jvm_common_buildpack_tarball_url}" \
32+
-o "${jvm_common_buildpack_tarball_path}"
33+
34+
tar -xzm --directory "${jvm_common_buildpack_dir}" --strip-components=1 -f "${jvm_common_buildpack_tarball_path}"
2535

2636
# This script translates non-JDBC compliant DATABASE_URL (and similar) environment variables into their
2737
# JDBC compatible counterparts and writes them to "JDBC_" prefixed environment variables. We source this script
2838
# here to allow customers to connect to their databases via JDBC during the build. If no database environment
2939
# variables are present, this script does nothing.
3040
# shellcheck source=/dev/null
31-
source "${jvm_common_buildpack_directory}/opt/jdbc.sh"
41+
source "${jvm_common_buildpack_dir}/opt/jdbc.sh"
3242

33-
# shellcheck source=/dev/null
34-
source "${jvm_common_buildpack_directory}/bin/java"
43+
# Run the main installation in a sub-shell to avoid it overriding library functions and global
44+
# variables in the host buildpack.
45+
(
46+
# shellcheck source=/dev/null
47+
source "${jvm_common_buildpack_dir}/bin/java"
3548

36-
# See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java
37-
install_openjdk "${build_directory}" "${host_buildpack_directory}"
49+
# See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java
50+
install_openjdk "${build_dir}" "${host_buildpack_dir}"
51+
)
52+
53+
# Since we run install_openjdk in a sub-shell, any environment variables set by it will not be available in this
54+
# (parent) shell. As documented in the jvm buildpack, we can source the modified export script from this (host)
55+
# buildpack to get the necessary changes.
56+
# shellcheck source=/dev/null
57+
source "${host_buildpack_dir}/export"
3858
}

0 commit comments

Comments
 (0)