Skip to content

Commit

Permalink
Require Java 11 for the build
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof committed Mar 15, 2024
1 parent 7eef4e0 commit d60682b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
# binary version is required and Pekko build will set the right
# full version from it.
scalaVersion: ["2.12", "2.13", "3.3"]
javaVersion: [8, 11, 17, 21]
javaVersion: [11, 17, 21]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
11 changes: 2 additions & 9 deletions project/Doc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ object UnidocRoot extends AutoPlugin {

lazy val pekkoSettings = UnidocRoot.CliOptions.genjavadocEnabled
.ifTrue(Seq(
JavaUnidoc / unidoc / javacOptions := {
if (JdkOptions.isJdk8) Seq("-Xdoclint:none")
else Seq("-Xdoclint:none", "--ignore-source-errors", "--no-module-directories")
}))
JavaUnidoc / unidoc / javacOptions := Seq("-Xdoclint:none", "--ignore-source-errors", "--no-module-directories")))
.getOrElse(Nil)

override lazy val projectSettings = {
Expand Down Expand Up @@ -213,11 +210,7 @@ object BootstrapGenjavadoc extends AutoPlugin {

override lazy val requires =
UnidocRoot.CliOptions.genjavadocEnabled
.ifTrue {
// require 11, fail fast for 8, 9, 10
require(JdkOptions.isJdk11orHigher, "Javadoc generation requires at least jdk 11")
sbtunidoc.GenJavadocPlugin
}
.ifTrue(sbtunidoc.GenJavadocPlugin)
.getOrElse(plugins.JvmPlugin)

override lazy val projectSettings = UnidocRoot.CliOptions.genjavadocEnabled
Expand Down
15 changes: 7 additions & 8 deletions project/Jdk9.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import sbt.Keys._
import sbt._

object Jdk9 extends AutoPlugin {
import JdkOptions.notOnJdk8
import JdkOptions.JavaVersion._

// The version 9 is special for any Java versions >= 9
Expand Down Expand Up @@ -59,15 +58,15 @@ object Jdk9 extends AutoPlugin {

lazy val compileJdk9Settings = Seq(
// following the scala-2.12, scala-sbt-1.0, ... convention
unmanagedSourceDirectories := notOnJdk8(additionalSourceDirectories.value),
scalacOptions := PekkoBuild.DefaultScalacOptions.value ++ notOnJdk8(Seq("-release", majorVersion.toString)),
javacOptions := PekkoBuild.DefaultJavacOptions ++ notOnJdk8(Seq("--release", majorVersion.toString)))
unmanagedSourceDirectories := additionalSourceDirectories.value,
scalacOptions := PekkoBuild.DefaultScalacOptions.value ++ Seq("-release", majorVersion.toString),
javacOptions := PekkoBuild.DefaultJavacOptions ++ Seq("--release", majorVersion.toString))

lazy val testJdk9Settings = Seq(
// following the scala-2.12, scala-sbt-1.0, ... convention
unmanagedSourceDirectories := notOnJdk8(additionalTestSourceDirectories.value),
scalacOptions := PekkoBuild.DefaultScalacOptions.value ++ notOnJdk8(Seq("-release", majorVersion.toString)),
javacOptions := PekkoBuild.DefaultJavacOptions ++ notOnJdk8(Seq("--release", majorVersion.toString)),
unmanagedSourceDirectories := additionalTestSourceDirectories.value,
scalacOptions := PekkoBuild.DefaultScalacOptions.value ++ Seq("-release", majorVersion.toString),
javacOptions := PekkoBuild.DefaultJavacOptions ++ Seq("--release", majorVersion.toString),
compile := compile.dependsOn(CompileJdk9 / compile).value,
classpathConfiguration := TestJdk9,
externalDependencyClasspath := (Test / externalDependencyClasspath).value)
Expand All @@ -80,7 +79,7 @@ object Jdk9 extends AutoPlugin {
// Since sbt-osgi upgrade to 0.9.5, the fullClasspath is no longer used on packaging when use sbt-osgi, so we have to
// add jdk9 products to dependencyClasspathAsJars instead.
// Compile / fullClasspath ++= (CompileJdk9 / exportedProducts).value)
Compile / dependencyClasspathAsJars ++= notOnJdk8((CompileJdk9 / exportedProducts).value))
Compile / dependencyClasspathAsJars ++= (CompileJdk9 / exportedProducts).value)

lazy val testSettings = Seq((Test / test) := {
(Test / test).value
Expand Down
11 changes: 0 additions & 11 deletions project/JdkOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ object JdkOptions extends AutoPlugin {
}
}

lazy val isJdk8: Boolean =
VersionNumber(specificationVersion).matchesSemVer(SemanticSelector(s"=1.8"))
lazy val isJdk11orHigher: Boolean =
VersionNumber(specificationVersion).matchesSemVer(SemanticSelector(">=11"))
lazy val isJdk17orHigher: Boolean =
VersionNumber(specificationVersion).matchesSemVer(SemanticSelector(">=17"))

Expand All @@ -55,8 +51,6 @@ object JdkOptions extends AutoPlugin {
"--add-opens=java.base/java.nio=ALL-UNNAMED" :: Nil
} else Nil

def notOnJdk8[T](values: Seq[T]): Seq[T] = if (isJdk8) Seq.empty[T] else values

def targetJdkScalacOptions(
targetSystemJdk: Boolean,
jdk8home: Option[File],
Expand All @@ -66,7 +60,6 @@ object JdkOptions extends AutoPlugin {
targetSystemJdk,
jdk8home,
fullJavaHomes,
Seq(if (scalaVersion.startsWith("3.")) "-Xtarget:8" else "release:8"),
(java8home: File) => Seq("-release", "8"))
def targetJdkJavacOptions(
targetSystemJdk: Boolean,
Expand All @@ -76,7 +69,6 @@ object JdkOptions extends AutoPlugin {
targetSystemJdk,
jdk8home,
fullJavaHomes,
Nil,
// '-release 8' would be a neater option here, but is currently not an
// option because it doesn't provide access to `sun.misc.Unsafe` https://github.com/akka/akka/issues/27079
(java8home: File) => Seq("-source", "8", "-target", "8", "-bootclasspath", java8home + "/jre/lib/rt.jar"))
Expand All @@ -85,12 +77,9 @@ object JdkOptions extends AutoPlugin {
targetSystemJdk: Boolean,
jdk8home: Option[File],
fullJavaHomes: Map[String, File],
jdk8options: Seq[String],
jdk11options: File => Seq[String]): Seq[String] =
if (targetSystemJdk)
Nil
else if (isJdk8)
jdk8options
else
jdk8home.orElse(fullJavaHomes.get("8")) match {
case Some(java8home) =>
Expand Down
19 changes: 5 additions & 14 deletions project/PekkoBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,6 @@ object PekkoBuild {
}
}

private def jvmGCLogOptions(isJdk11OrHigher: Boolean, isJdk8: Boolean): Seq[String] = {
if (isJdk11OrHigher)
// -Xlog:gc* is equivalent to -XX:+PrintGCDetails. See:
// https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-BE93ABDC-999C-4CB5-A88B-1994AAAC74D5
Seq("-Xlog:gc*")
else if (isJdk8) Seq("-XX:+PrintGCTimeStamps", "-XX:+PrintGCDetails")
else Nil
}

// -XDignore.symbol.file suppresses sun.misc.Unsafe warnings
final val DefaultJavacOptions = Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-XDignore.symbol.file")

Expand Down Expand Up @@ -227,8 +218,10 @@ object PekkoBuild {
// faster random source
"-Djava.security.egd=file:/dev/./urandom")

// -Xlog:gc* is equivalent to -XX:+PrintGCDetails. See:
// https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-BE93ABDC-999C-4CB5-A88B-1994AAAC74D5
defaults ++ CliOptions.runningOnCi
.ifTrue(jvmGCLogOptions(JdkOptions.isJdk11orHigher, JdkOptions.isJdk8))
.ifTrue(Seq("-Xlog:gc*"))
.getOrElse(Nil) ++
JdkOptions.versionSpecificJavaOptions
},
Expand Down Expand Up @@ -327,10 +320,8 @@ object PekkoBuild {
lazy val docLintingSettings = Seq(
compile / javacOptions ++= Seq("-Xdoclint:none"),
test / javacOptions ++= Seq("-Xdoclint:none"),
doc / javacOptions ++= {
if (JdkOptions.isJdk8) Seq("-Xdoclint:none")
else Seq("-Xdoclint:none", "--ignore-source-errors")
})
doc / javacOptions ++= Seq("-Xdoclint:none", "--ignore-source-errors")
)

def loadSystemProperties(fileName: String): Unit = {
import scala.collection.JavaConverters._
Expand Down
13 changes: 3 additions & 10 deletions project/TestExtras.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import sbt.Keys._
import sbt._

object TestExtras {
import JdkOptions.isJdk8
object Filter {
object Keys {
lazy val excludeTestNames = settingKey[Set[String]](
Expand Down Expand Up @@ -61,17 +60,11 @@ object TestExtras {
def shouldExist(description: String, filename: String): Unit =
require(file(filename).exists, s"$description should be run as part of the build")

val baseList =
List(
"The java JavaExtension.java" -> "actor-tests/target/test-reports/TEST-org.apache.pekko.actor.JavaExtension.xml")
val jdk9Only = List(
"The jdk9-only FlowPublisherSinkSpec.scala" -> "stream-tests/target/test-reports/TEST-org.apache.pekko.stream.scaladsl.FlowPublisherSinkSpec.xml",
val testsToCheck = List(
"The java JavaExtension.java" -> "actor-tests/target/test-reports/TEST-org.apache.pekko.actor.JavaExtension.xml",
"The jdk9-only FlowPublisherSinkSpec.scala" -> "stream-tests/target/test-reports/TEST-org.apache.pekko.stream.scaladsl.FlowPublisherSinkSpec.xml",
"The jdk9-only JavaFlowSupportCompileTest.java" -> "stream-tests/target/test-reports/TEST-org.apache.pekko.stream.javadsl.JavaFlowSupportCompileTest.xml")

val testsToCheck =
if (isJdk8) baseList
else baseList ::: jdk9Only

testsToCheck.foreach((shouldExist _).tupled)
})
}
Expand Down

0 comments on commit d60682b

Please sign in to comment.