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

Use Java release option #2825

Closed
wants to merge 7 commits into from
Closed
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
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,6 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
} else Seq()
}
)
.jvmSettings(
javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
)
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % MacrotaskExecutorVersion)

Expand Down Expand Up @@ -604,4 +601,7 @@ lazy val benchmarks = project
"-Dcats.effect.tracing.exceptions.enhanced=false"))
.enablePlugins(NoPublishPlugin, JmhPlugin)

lazy val docs = project.in(file("site-docs")).dependsOn(core.jvm).enablePlugins(MdocPlugin)
lazy val docs = project
.in(file("site-docs"))
.dependsOn(core.jvm)
.enablePlugins(MdocPlugin)
41 changes: 41 additions & 0 deletions project/Java8Target.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sbt._, Keys._
import sbtspiewak.SpiewakPlugin, SpiewakPlugin.autoImport._

object Java8Target extends AutoPlugin {

override def requires = SpiewakPlugin
override def trigger = allRequirements

override def projectSettings = Seq(
scalacOptions ++= {
val version = System.getProperty("java.version")

// The release flag controls what JVM platform APIs are called. We only want JDK 8 APIs
// in order to maintain compability with JDK 8.
val releaseFlag =
if (version.startsWith("1.8"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's factor this out as it is repeated:
val isJdk8: Boolean = System.getProperty("java.version").startsWith("1.8")

Seq()
else
Seq("-release", "8")

// The target flag is not implied by `-release` on Scala 2. We need to set it explicitly.
// The target flag controls the JVM bytecode version that is output by scalac.
val targetFlag =
if (isDotty.value || version.startsWith("1.8"))
Seq()
else if (scalaVersion.value.startsWith("2.12"))
Seq("-target:jvm-1.8")
else
Seq("-target:8")

releaseFlag ++ targetFlag
},

javacOptions ++= {
val version = System.getProperty("java.version")
if (version.startsWith("1.8"))
Seq()
else
Seq("--release", "8")
})
}