Skip to content

Commit 16d3794

Browse files
committed
Add CHANGELOG entry
1 parent d2976d4 commit 16d3794

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
* Replace sbt-extras with direct sbt launcher installation. ([#291](https://github.com/heroku/heroku-buildpack-scala/pull/291))
56
* Remove build directory symlinking. Modern sbt versions no longer require a stable build path for caching. ([#290](https://github.com/heroku/heroku-buildpack-scala/pull/290))
67

78
## [v103] - 2025-10-27

bin/compile

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ if has_old_preset_sbt_opts; then
131131
EOF
132132
fi
133133

134+
135+
# Copy the target dir from cache
136+
util::cache_copy "target" "${CACHE_DIR}" "${BUILD_DIR}"
137+
134138
if [[ -n "${SBT_PROJECT}" ]]; then
135139
SBT_TASKS="${SBT_PROJECT}/compile ${SBT_PROJECT}/stage"
136140
else
@@ -161,24 +165,35 @@ sbt_boot_dir="${CACHE_DIR}/sbt_boot"
161165
util::prepend_to_env "SBT_OPTS" "-Dsbt.boot.directory=${sbt_boot_dir}"
162166
mkdir -p "${sbt_boot_dir}"
163167

164-
# Recreate the sbt global directory on each build with the current Heroku plugins and settings.
165168
# See: https://www.scala-sbt.org/1.x/docs/Command-Line-Reference.html
166169
sbt_global_dir="${CACHE_DIR}/sbt_global"
167170
util::prepend_to_env "SBT_OPTS" "-Dsbt.global.base=${sbt_global_dir}"
168-
rm -rf "${sbt_global_dir}"
169171
mkdir -p "${sbt_global_dir}"
170172

171-
# Install the Heroku sbt plugin
172-
mkdir -p "${sbt_global_dir}/plugins"
173+
# Install the Heroku sbt plugin if the exising version differs (or is missing). We do this conditionally to
174+
# ensure we can cache the compiled class files of the plugin between builds, speeding up the build overall.
173175
case "${sbt_version}" in
174176
1.*)
175-
cp "${BUILDPACK_DIR}/opt/HerokuBuildpackPlugin_sbt1.scala" "${sbt_global_dir}/plugins/HerokuBuildpackPlugin.scala"
177+
plugin_source_path="${BUILDPACK_DIR}/opt/HerokuBuildpackPlugin_sbt1.scala"
176178
;;
177179
*)
178-
cp "${BUILDPACK_DIR}/opt/HerokuBuildpackPlugin.scala" "${sbt_global_dir}/plugins/HerokuBuildpackPlugin.scala"
180+
plugin_source_path="${BUILDPACK_DIR}/opt/HerokuBuildpackPlugin.scala"
179181
;;
180182
esac
181183

184+
plugins_dir="${sbt_global_dir}/plugins"
185+
plugin_destination_path="${plugins_dir}/HerokuBuildpackPlugin.scala"
186+
source_checksum="$(sha256sum "${plugin_source_path}" | awk '{print $1}')"
187+
188+
if [[ ! -f "${plugin_destination_path}" ]] || [[ "${source_checksum}" != "$(sha256sum "${plugin_destination_path}" | awk '{print $1}')" ]]; then
189+
# We remove the whole directory since we also want to remove the (cached) compiled files
190+
# for the older version of the plugin in the ./target directory.
191+
rm -rf "${plugins_dir}"
192+
193+
mkdir -p "${plugins_dir}"
194+
cp "${plugin_source_path}" "${plugin_destination_path}"
195+
fi
196+
182197
sbt::install_sbt_launcher "${sbt_version}" "${CACHE_DIR}/sbt-launcher"
183198

184199
# Collect metrics
@@ -196,12 +211,16 @@ fi
196211

197212
# build app
198213
cd "${BUILD_DIR}"
214+
199215
run_sbt "${SBT_TASKS}"
200216

201217
if [[ -z "${DISABLE_DEPENDENCY_CLASSPATH_LOG:-}" ]]; then
202218
write_sbt_dependency_classpath_log
203219
fi
204220

221+
# Copy the target dir to cache
222+
util::cache_copy "target" "${BUILD_DIR}" "${CACHE_DIR}"
223+
205224
# drop useless directories from slug for play and sbt-native-launcher only
206225
if is_sbt_native_packager "${BUILD_DIR}" || is_play "${BUILD_DIR}"; then
207226
if [[ "${KEEP_SBT_CACHE:-}" != "true" ]]; then
@@ -220,12 +239,10 @@ fi
220239
profile_script="${BUILD_DIR}/.profile.d/scala.sh"
221240
mkdir -p "$(dirname "${profile_script}")"
222241
cat <<-EOF >"${profile_script}"
223-
export SBT_HOME="\$HOME/${SBT_USER_HOME}"
224242
export PATH="\$SBT_HOME/bin:\$PATH"
225243
EOF
226244

227245
# write export script
228246
cat <<-EOF >"${BASE_DIR}/export"
229-
export SBT_HOME="${BUILD_DIR}/${SBT_USER_HOME}"
230247
export PATH="\$SBT_HOME/bin:\$PATH"
231248
EOF

lib/sbt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function sbt::install_sbt_launcher() {
2121
cat <<-EOF >"${sbt_launcher_dir}/bin/sbt"
2222
#!/usr/bin/env bash
2323
script_dir="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
24-
java -jar "\${script_dir}/../sbt-launch-${sbt_version}.jar" "\$@"
24+
java \${SBT_OPTS:-} -jar "\${script_dir}/../sbt-launch-${sbt_version}.jar" "\$@"
2525
EOF
2626

2727
chmod +x "${sbt_launcher_dir}/bin/sbt"

test/spec/cache_spec.rb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@
1010
expect(clean_output(app.output)).to match(Regexp.new(<<~REGEX, Regexp::MULTILINE))
1111
remote: -----> Scala app detected
1212
remote: -----> Installing Azul Zulu OpenJDK 21.0.[0-9]+
13+
remote: -----> Downloading sbt launcher 1.11.7...
14+
remote: -----> Setting up sbt launcher...
1315
remote: -----> Running: sbt compile stage
14-
remote: Downloading sbt launcher for 1.11.7:
15-
remote: From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.11.7/sbt-launch-1.11.7.jar
16-
remote: To /tmp/[^/]+/.sbt_home/launchers/1.11.7/sbt-launch.jar
17-
remote: Downloading sbt launcher 1.11.7 md5 hash:
18-
remote: From https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.11.7/sbt-launch-1.11.7.jar.md5
19-
remote: To /tmp/[^/]+/.sbt_home/launchers/1.11.7/sbt-launch.jar.md5
20-
remote: /tmp/[^/]+/.sbt_home/launchers/1.11.7/sbt-launch.jar: OK
2116
remote: \\[info\\] \\[launcher\\] getting org.scala-sbt sbt 1.11.7 \\(this may take some time\\)...
2217
remote: \\[info\\] \\[launcher\\] getting Scala 2.12.20 \\(for sbt\\)...
2318
remote: \\[info\\] welcome to sbt 1.11.7 \\(Azul Systems, Inc. Java 21.0.[0-9]+\\)
24-
remote: \\[info\\] loading global plugins from /tmp/[^/]+/.sbt_home/plugins
25-
remote: \\[info\\] compiling 1 Scala source to /tmp/[^/]+/.sbt_home/plugins/target/scala-2.12/sbt-1.0/classes ...
19+
remote: \\[info\\] loading global plugins from .*/plugins
20+
remote: \\[info\\] compiling 1 Scala source to .* ...
2621
remote: \\[info\\] Non-compiled module 'compiler-bridge_2.12' for Scala 2.12.20. Compiling...
2722
remote: \\[info\\] Compilation completed in .*s.
2823
remote: \\[info\\] done compiling
@@ -48,9 +43,6 @@
4843
remote: \\[info\\] Wrote /tmp/[^/]+/target/scala-2.13/sbt-0-11-7-play-3-x-scala-2-13-x_2.13-1.0-SNAPSHOT.pom
4944
remote: \\[success\\] Total time: .*
5045
remote: -----> Collecting dependency information
51-
remote: -----> Dropping ivy cache from the slug
52-
remote: -----> Dropping sbt boot dir from the slug
53-
remote: -----> Dropping sbt cache dir from the slug
5446
remote: -----> Dropping compilation artifacts from the slug
5547
remote: -----> Discovering process types
5648
remote: Procfile declares types -> \\(none\\)
@@ -66,9 +58,10 @@
6658
expect(clean_output(app.output)).to match(Regexp.new(<<~REGEX, Regexp::MULTILINE))
6759
remote: -----> Scala app detected
6860
remote: -----> Installing Azul Zulu OpenJDK 21.0.[0-9]+
61+
remote: -----> Setting up sbt launcher...
6962
remote: -----> Running: sbt compile stage
7063
remote: \\[info\\] welcome to sbt 1.11.7 \\(Azul Systems, Inc. Java 21.0.[0-9]+\\)
71-
remote: \\[info\\] loading global plugins from /tmp/[^/]+/.sbt_home/plugins
64+
remote: \\[info\\] loading global plugins from .*/plugins
7265
remote: \\[info\\] loading settings for project [^\\s]+-build from plugins.sbt...
7366
remote: \\[info\\] loading project definition from /tmp/[^/]+/project
7467
remote: \\[info\\] loading settings for project root from build.sbt...
@@ -89,9 +82,6 @@
8982
remote: \\[info\\] Wrote /tmp/[^/]+/target/scala-2.13/sbt-0-11-7-play-3-x-scala-2-13-x_2.13-1.0-SNAPSHOT.pom
9083
remote: \\[success\\] Total time: .*
9184
remote: -----> Collecting dependency information
92-
remote: -----> Dropping ivy cache from the slug
93-
remote: -----> Dropping sbt boot dir from the slug
94-
remote: -----> Dropping sbt cache dir from the slug
9585
remote: -----> Dropping compilation artifacts from the slug
9686
remote: -----> Discovering process types
9787
remote: Procfile declares types -> \\(none\\)

0 commit comments

Comments
 (0)