diff --git a/build.sbt b/build.sbt index 23fdd4ddd4..ad1cf85010 100644 --- a/build.sbt +++ b/build.sbt @@ -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) @@ -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) diff --git a/project/Java8Target.scala b/project/Java8Target.scala new file mode 100644 index 0000000000..f8c296d896 --- /dev/null +++ b/project/Java8Target.scala @@ -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")) + 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") + }) +}