From 975470a5021daf9155b5988690c6158da406ff9a Mon Sep 17 00:00:00 2001 From: Ostrzyciel Date: Sat, 29 Mar 2025 01:06:53 +0100 Subject: [PATCH] Get rid of unsafe access warnings on JDK 24 --- build.sbt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 338c0c4..2ab2560 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,6 @@ ThisBuild / semanticdbEnabled := true -ThisBuild / scalaVersion := "3.6.4" +lazy val scalaV = "3.6.4" +ThisBuild / scalaVersion := scalaV resolvers += "Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots" @@ -12,6 +13,14 @@ addCommandAlias("fixAll", "scalafixAll; scalafmtAll") def isDevBuild: Boolean = sys.env.get("DEV_BUILD").exists(s => s != "0" && s != "false") +lazy val baseGraalOptions = Seq( + // If running on Scala <3.8 and JDK >=24, we need to allow unsafe memory access. + // Otherwise, we get annoying warnings on startup. + // https://github.com/scala/scala3/issues/9013 + // Remove this after moving to Scala 3.8 + if (scalaV.split('.')(1).toInt < 8) Some("-J--sun-misc-unsafe-memory-access=allow") else None, +).flatten + lazy val root = (project in file(".")) .enablePlugins( BuildInfoPlugin, @@ -45,5 +54,8 @@ lazy val root = (project in file(".")) // GraalVM settings Compile / mainClass := Some("eu.neverblink.jelly.cli.App"), // Do a fast build if it's a dev build - graalVMNativeImageOptions := (if (isDevBuild) Seq("-Ob") else Seq("--emit build-report")), + graalVMNativeImageOptions := ( + if (isDevBuild) Seq("-Ob") + else Seq("--emit build-report") + ) ++ baseGraalOptions, )