Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on Java 21 (but keep JDK 8 compatibility) #396

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"