Skip to content

Commit 4017564

Browse files
authored
Add warning/error for unsupported sbt 0.x and 2.x versions (#281)
1 parent c89c523 commit 4017564

File tree

22 files changed

+247
-54
lines changed

22 files changed

+247
-54
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
* Add error for unsupported sbt `2.x` versions. ([#281](https://github.com/heroku/heroku-buildpack-scala/pull/281))
6+
* Add warning for unsupported sbt `0.x` versions. ([#281](https://github.com/heroku/heroku-buildpack-scala/pull/281))
57
* Remove automatic deletion of `project/play-fork-run.sbt` files. Maintainers of legacy apps can consult the PR description for background and how to fix their project in the unlikely case it's necessary. ([#280](https://github.com/heroku/heroku-buildpack-scala/pull/280))
68
* Deprecate Scala buildpack configuration via system.properties. A warning is now shown when Scala buildpack configuration properties (like `sbt.clean`, `sbt.project`, etc.) are detected in system.properties. Use environment variables instead. This does not affect `java.runtime.version` which remains supported. ([#279](https://github.com/heroku/heroku-buildpack-scala/pull/279))
79
* Remove partial CNB functionality. ([#276](https://github.com/heroku/heroku-buildpack-scala/pull/276))

bin/compile

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,68 @@ for DIR in ${CACHED_DIRS}; do
9090
cache_copy "${DIR}" "${CACHE_DIR}" "${BUILD_DIR}"
9191
done
9292

93-
# these are preliminary checks. actual version check happens below when attempting to download sbt boot.properties
94-
if ! test -e project/build.properties; then
93+
sbt_version="$(java_properties::get "${BUILD_DIR}/project/build.properties" "sbt.version")"
94+
metrics::set_string "sbt_version" "${sbt_version:-"unknown"}"
95+
96+
if [[ -z "${sbt_version}" ]]; then
9597
output::error <<-EOF
96-
Your scala project must include project/build.properties and define sbt.version
98+
Error: sbt version cannot be determined.
99+
100+
As part of your build definition you must specify the version of sbt that
101+
your build uses. This ensures consistent results across different environments.
102+
103+
To fix this issue, create a file named project/build.properties that specifies
104+
the sbt version as follows:
105+
106+
sbt.version=1.11.7
107+
108+
For more information, see:
109+
https://www.scala-sbt.org/1.x/docs/Basic-Def.html#Specifying+the+sbt+version
97110
EOF
98111

99112
exit 1
100113
fi
101114

102-
if ! (has_supported_sbt_version "${BUILD_DIR}" || has_supported_sbt_1_version "${BUILD_DIR}"); then
115+
case "${sbt_version}" in
116+
0.*)
117+
output::warning <<-EOF
118+
Warning: Unsupported sbt version detected.
119+
120+
This buildpack does not officially support sbt ${sbt_version}. You are using
121+
an end-of-life version that no longer receives security updates or bug fixes.
122+
Support for sbt 0.x was ended by the upstream sbt project on November 30, 2018.
123+
124+
Please upgrade to sbt 1.x for active support.
125+
126+
The buildpack will attempt to build your application, but compatibility
127+
is not guaranteed and may break at any time.
128+
129+
For more information:
130+
- https://web.archive.org/web/20210918065807/https://www.lightbend.com/blog/scala-sbt-127-patchnotes
131+
132+
Upgrade guide:
133+
- https://www.scala-sbt.org/1.x/docs/Migrating-from-sbt-013x.html
134+
EOF
135+
;;
136+
2.*)
103137
output::error <<-EOF
104-
You have defined an unsupported sbt.version in project/build.properties
105-
For sbt 0.x you must use a version >= 0.11, for sbt 1.x you must use a version >= 1.1
138+
Error: Unsupported sbt version detected.
139+
140+
This buildpack does not currently support sbt 2.x. You are using sbt ${sbt_version}.
141+
142+
Support for sbt 2.x will be added in a future buildpack release. In the
143+
meantime, please use the latest stable sbt 1.x version for your deployments.
144+
145+
To continue, update project/build.properties to use sbt 1.x.
146+
147+
For more information:
148+
- Latest sbt 1.x releases: https://github.com/sbt/sbt/releases
149+
- sbt 2.x changes: https://www.scala-sbt.org/2.x/docs/en/changes/sbt-2.0-change-summary.html
106150
EOF
107151

108152
exit 1
109-
fi
153+
;;
154+
esac
110155

111156
if has_old_preset_sbt_opts; then
112157
output::warning <<-EOF
@@ -123,8 +168,6 @@ if has_old_preset_sbt_opts; then
123168
EOF
124169
fi
125170

126-
SBT_VERSION="$(get_supported_sbt_version "${BUILD_DIR}")"
127-
128171
if [[ -n "${SBT_PROJECT}" ]]; then
129172
SBT_TASKS="${SBT_PROJECT}/compile ${SBT_PROJECT}/stage"
130173
else
@@ -145,19 +188,22 @@ fi
145188
install_sbt_extras "${BUILDPACK_DIR}/opt" "${SBT_BINDIR}"
146189

147190
# copy in heroku sbt plugin
148-
if has_supported_sbt_1_version "${BUILD_DIR}"; then
191+
case "${sbt_version}" in
192+
1.*)
149193
HEROKU_PLUGIN="HerokuBuildpackPlugin_sbt1.scala"
150-
else
194+
;;
195+
*)
151196
HEROKU_PLUGIN="HerokuBuildpackPlugin.scala"
152-
fi
197+
;;
198+
esac
199+
153200
mkdir -p "${SBT_USER_HOME}/plugins"
154201
rm -f "${SBT_USER_HOME}/plugins/HerokuPlugin.scala" # remove the old ambiguously named plugin
155202
rm -f "${SBT_USER_HOME}/plugins/HerokuBuildpackPlugin_sbt1.scala" # remove the old poorly named plugin
156203
rm -f "${SBT_USER_HOME}/plugins/HerokuBuildpackPlugin.scala" # remove the old plugin
157204
cp -p "${BUILDPACK_DIR}/opt/${HEROKU_PLUGIN}" "${SBT_USER_HOME}/plugins/HerokuBuildpackPlugin.scala"
158205

159206
# Collect metrics
160-
metrics::set_string "sbt_version" "${SBT_VERSION:-unknown}"
161207

162208
if is_sbt_native_packager "${BUILD_DIR}"; then
163209
metrics::set_raw "uses_sbt_native_packager" "true"

lib/common.sh

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
set -euo pipefail
44

5-
SBT_0_VERSION_PATTERN='sbt\.version=\(0\.1[1-3]\.[0-9]\+\(-[a-zA-Z0-9_]\+\)*\)$'
6-
SBT_1_VERSION_PATTERN='sbt\.version=\(1\.[1-9][0-9]*\.[0-9]\+\(-[a-zA-Z0-9_]\+\)*\)$'
7-
85
is_play() {
96
local app_dir="${1}"
107

@@ -32,44 +29,6 @@ is_sbt_native_packager() {
3229
fi
3330
}
3431

35-
get_supported_sbt_version() {
36-
local ctx_dir="${1}"
37-
local sbt_version_pattern="${2:-${SBT_0_VERSION_PATTERN}}"
38-
if test -e "${ctx_dir}/project/build.properties"; then
39-
sbt_version_line="$(grep -P '[ \t]*sbt\.version[ \t]*=' "${ctx_dir}"/project/build.properties | sed -E -e 's/[ \t\r\n]//g' || true)"
40-
sbt_version="$(expr "${sbt_version_line}" : "${sbt_version_pattern}")"
41-
if [[ "${sbt_version}" != 0 ]]; then
42-
echo "${sbt_version}"
43-
else
44-
echo ""
45-
fi
46-
else
47-
echo ""
48-
fi
49-
}
50-
51-
has_supported_sbt_version() {
52-
local ctx_dir="${1}"
53-
local supported_version
54-
supported_version="$(get_supported_sbt_version "${ctx_dir}" "${SBT_0_VERSION_PATTERN}")"
55-
if [[ -n "${supported_version}" ]]; then
56-
return 0
57-
else
58-
return 1
59-
fi
60-
}
61-
62-
has_supported_sbt_1_version() {
63-
local ctx_dir="${1}"
64-
local supported_version
65-
supported_version="$(get_supported_sbt_version "${ctx_dir}" "${SBT_1_VERSION_PATTERN}")"
66-
if [[ -n "${supported_version}" ]]; then
67-
return 0
68-
else
69-
return 1
70-
fi
71-
}
72-
7332
has_old_preset_sbt_opts() {
7433
if [[ "${SBT_OPTS:-}" = "-Xmx384m -Xss512k -XX:+UseCompressedOops" ]]; then
7534
return 0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
.bsp
3+
.idea
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name := "sbt-1.11.7-minimal-with-native-packager"
2+
3+
scalaVersion := "2.13.17"
4+
5+
libraryDependencies ++= Seq(
6+
"dev.zio" %% "zio-http" % "3.5.1"
7+
)
8+
9+
import NativePackagerKeys._
10+
11+
packageArchetype.java_application
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.18
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.7.5-RC2")
2+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.heroku
2+
3+
import zio._
4+
import zio.http._
5+
6+
object App extends ZIOAppDefault {
7+
private val routes = Routes(
8+
Method.GET / Root -> handler(Response.text("Hello from Scala!"))
9+
)
10+
11+
def run = for {
12+
port <- System.env("PORT").map(_.flatMap(_.toIntOption).getOrElse(8080))
13+
_ <- Server.serve(routes).provide(Server.defaultWithPort(port))
14+
} yield ()
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java.runtime.version=11
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
.bsp
3+
.idea

0 commit comments

Comments
 (0)