Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

* Improve OpenJDK installation via jvm-common buildpack to prevent function overrides and fix environment variable handling ([#275](https://github.com/heroku/heroku-buildpack-java/pull/275))
* Improve detection error message with better user experience and guidance for other build tools ([#270](https://github.com/heroku/heroku-buildpack-java/pull/270))


Expand Down
30 changes: 25 additions & 5 deletions lib/openjdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ function openjdk::install_openjdk_via_jvm_common_buildpack() {
local jvm_common_buildpack_dir
jvm_common_buildpack_dir=$(mktemp -d)

curl --silent --show-error --fail --retry 3 --retry-connrefused --connect-timeout 5 --location "${jvm_common_buildpack_tarball_url}" -o "${jvm_common_buildpack_tarball_path}"
curl \
--connect-timeout 3 \
--max-time 60 \
--retry 5 \
--retry-connrefused \
--no-progress-meter \
--fail \
--location \
"${jvm_common_buildpack_tarball_url}" \
-o "${jvm_common_buildpack_tarball_path}"

tar -xzm --directory "${jvm_common_buildpack_dir}" --strip-components=1 -f "${jvm_common_buildpack_tarball_path}"

# This script translates non-JDBC compliant DATABASE_URL (and similar) environment variables into their
Expand All @@ -30,9 +40,19 @@ function openjdk::install_openjdk_via_jvm_common_buildpack() {
# shellcheck source=/dev/null
source "${jvm_common_buildpack_dir}/opt/jdbc.sh"

# shellcheck source=/dev/null
source "${jvm_common_buildpack_dir}/bin/java"
# Run the main installation in a sub-shell to avoid it overriding library functions and global
# variables in the host buildpack.
(
# shellcheck source=/dev/null
source "${jvm_common_buildpack_dir}/bin/java"

# See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java
install_openjdk "${build_dir}" "${host_buildpack_dir}"
# See: https://github.com/heroku/heroku-buildpack-jvm-common/blob/main/bin/java
install_openjdk "${build_dir}" "${host_buildpack_dir}"
)

# Since we run install_openjdk in a sub-shell, any environment variables set by it will not be available in this
# (parent) shell. As documented in the jvm buildpack, we can source the modified export script from this (host)
# buildpack to get the necessary changes.
# shellcheck source=/dev/null
source "${host_buildpack_dir}/export"
}