Skip to content

Commit

Permalink
Build on Java 21 (but keep JDK 8 compatibility) (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault authored Nov 19, 2024
1 parent 1a1c1fa commit 178533b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
6 changes: 2 additions & 4 deletions .github/scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ if [ "$IS_UNIX" == "true" ]; then
sbt \
'set version in ThisBuild := "'"$TEST_VERSION"'"' \
publishLocal
echo "Running JDK 11 tests…"
# test that things work from JDK 11
# not actually building things from it, running into weird proguard issues…
echo "Running JDK 8 tests…"

TEST_JDK="adopt:1.11.0-7"
TEST_JDK="adoptium:8"
eval "$(cs java --jvm "$TEST_JDK" --env)"

java -Xmx32m -version
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: coursier/cache-action@v6
- uses: coursier/setup-action@v1.3
with:
jvm: 8
jvm: 21
apps: sbt
- name: Test
run: ./.github/scripts/ci.sh
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: coursier/cache-action@v6
- uses: coursier/setup-action@v1.3
with:
jvm: 8
jvm: 21
- run: .github/scripts/gpg-setup.sh
shell: bash
env:
Expand Down
8 changes: 6 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ inThisBuild(List(

lazy val finalPackageBin = taskKey[File]("")

lazy val isJava9OrMore = sys.props.get("java.version").exists(!_.startsWith("1."))

lazy val interface = project
.enablePlugins(SbtProguard)
.settings(
Expand Down Expand Up @@ -121,11 +123,13 @@ lazy val interface = project
"-keep class coursierapi.** {\n public protected *;\n}"
)

val isJava9OrMore = sys.props.get("java.version").exists(!_.startsWith("1."))
val maybeJava9Options =
if (isJava9OrMore) {
val javaHome = sys.props.getOrElse("java.home", ???)
Seq(s"-libraryjars $javaHome/jmods/java.base.jmod")
Seq(
s"-libraryjars $javaHome/jmods/java.base.jmod",
s"-libraryjars $javaHome/jmods/java.xml.jmod"
)
}
else
Nil
Expand Down
37 changes: 33 additions & 4 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,50 @@ import com.typesafe.tools.mima.plugin.MimaPlugin
import sbt._
import sbt.Keys._

import scala.util.Properties

import java.util.Locale

object Settings {

def scala213 = "2.13.15"

def scala212 = "2.12.20"

private def isArm64 =
Option(System.getProperty("os.arch")).map(_.toLowerCase(Locale.ROOT)) match {
case Some("aarch64" | "arm64") => true
case _ => false
}
private lazy val java8Home = Option(System.getenv("COURSIER_INTERFACE_JAVA8_HOME")).getOrElse {
val jvmId =
if (Properties.isMac && isArm64)
// no native JDK 8 on Mac ARM, using amd64 one
"https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u432-b06/OpenJDK8U-jdk_x64_mac_hotspot_8u432b06.tar.gz"
else
"adoptium:8"
os.proc("cs", "java-home", "--jvm", jvmId)
.call()
.out.trim()
}
private lazy val rtJar = {
val path = os.Path(java8Home) / "jre/lib/rt.jar"
assert(os.isFile(path))
path
}
lazy val shared = Seq(
scalaVersion := scala213,
crossScalaVersions := Seq(scala213, scala212),
scalacOptions += "-target:jvm-1.8",
scalacOptions ++= Seq("--release", "8"),
javacOptions ++= Seq(
"-source", "1.8",
"-target", "1.8"
"-source", "8",
"-target", "8",
"-bootclasspath", rtJar.toString
),
Compile / doc / javacOptions := Seq("-source", "1.8")
Compile / doc / javacOptions := Seq(
"-source", "8",
"-bootclasspath", rtJar.toString
)
)

private val filterOut = Set("0.0.1")
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1")
addSbtPlugin("com.lightbend.sbt" % "sbt-proguard" % "0.4.0")

libraryDependencies += "com.eed3si9n.jarjarabrams" %% "jarjar-abrams-core" % "1.14.0"

libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.11.3"

0 comments on commit 178533b

Please sign in to comment.