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 1 commit
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
45 changes: 0 additions & 45 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -255,32 +255,6 @@ val jsProjects: Seq[ProjectReference] =
val undocumentedRefs =
jsProjects ++ Seq[ProjectReference](benchmarks, example.jvm, tests.jvm, tests.js)

lazy val releaseSettings = 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
}
)

lazy val root = project
.in(file("."))
.aggregate(rootJVM, rootJS)
Expand Down Expand Up @@ -322,7 +296,6 @@ lazy val kernel = crossProject(JSPlatform, JVMPlatform)
.cross(CrossVersion.for3Use2_13)
.exclude("org.scala-js", "scala-js-macrotask-executor_sjs1_2.13")
)
.settings(releaseSettings)
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % MacrotaskExecutorVersion % Test
)
Expand All @@ -344,7 +317,6 @@ lazy val kernelTestkit = crossProject(JSPlatform, JVMPlatform)
ProblemFilters.exclude[DirectMissingMethodProblem](
"cats.effect.kernel.testkit.TestContext.this"))
)
.settings(releaseSettings)

/**
* The laws which constrain the abstractions. This is split from kernel to avoid jar file and
Expand All @@ -360,7 +332,6 @@ lazy val laws = crossProject(JSPlatform, JVMPlatform)
"org.typelevel" %%% "cats-laws" % CatsVersion,
"org.typelevel" %%% "discipline-specs2" % DisciplineVersion % Test)
)
.settings(releaseSettings)

/**
* Concrete, production-grade implementations of the abstractions. Or, more simply-put: IO. Also
Expand Down Expand Up @@ -502,16 +473,6 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
} else Seq()
}
)
.settings(releaseSettings)
.jvmSettings(
javacOptions ++= {
val version = System.getProperty("java.version")
if (version.startsWith("1.8"))
Seq()
else
Seq("--release", "8")
}
)
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % MacrotaskExecutorVersion)

Expand All @@ -531,7 +492,6 @@ lazy val testkit = crossProject(JSPlatform, JVMPlatform)
.exclude("org.scala-js", "scala-js-macrotask-executor_sjs1_2.13")
)
)
.settings(releaseSettings)

/**
* Unit tests for the core project, utilizing the support provided by testkit.
Expand Down Expand Up @@ -560,7 +520,6 @@ lazy val tests: CrossProject = crossProject(JSPlatform, JVMPlatform)
Seq.empty
}
)
.settings(releaseSettings)
.jsSettings(
Compile / scalaJSUseMainModuleInitializer := true,
Compile / mainClass := Some("catseffect.examples.JSRunner"),
Expand Down Expand Up @@ -614,7 +573,6 @@ lazy val std = crossProject(JSPlatform, JVMPlatform)
ProblemFilters.exclude[MissingClassProblem]("cats.effect.std.Console$SyncConsole")
)
)
.settings(releaseSettings)
.jsSettings(
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % MacrotaskExecutorVersion % Test
)
Expand All @@ -628,7 +586,6 @@ lazy val example = crossProject(JSPlatform, JVMPlatform)
.dependsOn(core)
.enablePlugins(NoPublishPlugin)
.settings(name := "cats-effect-example")
.settings(releaseSettings)
.jsSettings(scalaJSUseMainModuleInitializer := true)

/**
Expand All @@ -642,11 +599,9 @@ lazy val benchmarks = project
javaOptions ++= Seq(
"-Dcats.effect.tracing.mode=none",
"-Dcats.effect.tracing.exceptions.enhanced=false"))
.settings(releaseSettings)
.enablePlugins(NoPublishPlugin, JmhPlugin)

lazy val docs = project
.in(file("site-docs"))
.dependsOn(core.jvm)
.settings(releaseSettings)
.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")
})
}