Skip to content

Commit 122f1c4

Browse files
Better Java version parsing
Co-authored-by: David Gregory <[email protected]>
1 parent fd4670f commit 122f1c4

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

settings/src/main/scala/org/typelevel/sbt/TypelevelSettingsPlugin.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ object TypelevelSettingsPlugin extends AutoPlugin {
278278
jdkRelease.fold(default) {
279279
case 8 if isJava8 => default
280280
case n if n >= 8 =>
281-
if (javaRuntimeVersion < n) {
281+
if (javaMajorVersion < n) {
282282
sys.error(
283-
s"Target JDK is $n but you are using an older JDK $javaRuntimeVersion. Please switch to JDK >= $n.")
283+
s"Target JDK is $n but you are using an older JDK $javaMajorVersion. Please switch to JDK >= $n.")
284284
} else {
285285
f(n)
286286
}
@@ -289,17 +289,14 @@ object TypelevelSettingsPlugin extends AutoPlugin {
289289
s"Target JDK is $n, which is not supported by `sbt-typelevel`. Please select a JDK >= 8.")
290290
}
291291

292-
private val javaRuntimeVersion: Int =
293-
System.getProperty("java.version").split("""\.""") match {
294-
case Array("1", "8", _*) => 8
295-
case Array(feature, _*) => feature.toInt
296-
}
292+
private val javaMajorVersion: Int =
293+
System.getProperty("java.version").stripPrefix("1.").takeWhile(_.isDigit).toInt
297294

298-
private val isJava8: Boolean = javaRuntimeVersion == 8
295+
private val isJava8: Boolean = javaMajorVersion == 8
299296

300297
private val javaApiMappings = {
301298
// scaladoc doesn't support this automatically before 2.13
302-
val baseUrl = javaRuntimeVersion match {
299+
val baseUrl = javaMajorVersion match {
303300
case v if v < 11 => url(s"https://docs.oracle.com/javase/${v}/docs/api/")
304301
case v => url(s"https://docs.oracle.com/en/java/javase/${v}/docs/api/java.base/")
305302
}

0 commit comments

Comments
 (0)