From 810535b69b51bfd121bda2edbe8ce3aee127ccf2 Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Wed, 16 Feb 2022 10:56:24 +0100 Subject: [PATCH 1/7] Use Java release option --- build.sbt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 23fdd4ddd4..0a9d1dad19 100644 --- a/build.sbt +++ b/build.sbt @@ -474,7 +474,13 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) } ) .jvmSettings( - javacOptions ++= Seq("-source", "1.8", "-target", "1.8") + 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) From cc0215bcc2dd467f9685adef5bb7c2f017bc1dcb Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Wed, 16 Feb 2022 11:30:34 +0100 Subject: [PATCH 2/7] Use Scala release option --- build.sbt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 0a9d1dad19..62ae46db46 100644 --- a/build.sbt +++ b/build.sbt @@ -255,6 +255,10 @@ val jsProjects: Seq[ProjectReference] = val undocumentedRefs = jsProjects ++ Seq[ProjectReference](benchmarks, example.jvm, tests.jvm, tests.js) +lazy val releaseSettings = Seq( + scalacOptions ++= Seq("-release", "8") +) + lazy val root = project .in(file(".")) .aggregate(rootJVM, rootJS) @@ -296,6 +300,7 @@ 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 ) @@ -317,6 +322,7 @@ 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 @@ -332,6 +338,7 @@ 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 @@ -473,6 +480,7 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) } else Seq() } ) + .settings(releaseSettings) .jvmSettings( javacOptions ++= { val version = System.getProperty("java.version") @@ -501,6 +509,7 @@ 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. @@ -529,6 +538,7 @@ lazy val tests: CrossProject = crossProject(JSPlatform, JVMPlatform) Seq.empty } ) + .settings(releaseSettings) .jsSettings( Compile / scalaJSUseMainModuleInitializer := true, Compile / mainClass := Some("catseffect.examples.JSRunner"), @@ -582,6 +592,7 @@ 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 ) @@ -595,6 +606,7 @@ lazy val example = crossProject(JSPlatform, JVMPlatform) .dependsOn(core) .enablePlugins(NoPublishPlugin) .settings(name := "cats-effect-example") + .settings(releaseSettings) .jsSettings(scalaJSUseMainModuleInitializer := true) /** @@ -608,6 +620,11 @@ 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).enablePlugins(MdocPlugin) +lazy val docs = project + .in(file("site-docs")) + .dependsOn(core.jvm) + .settings(releaseSettings) + .enablePlugins(MdocPlugin) From 92e9fbe1cf63763cb4b07d829fbc7a2edb3ad430 Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Wed, 16 Feb 2022 11:57:03 +0100 Subject: [PATCH 3/7] The Java runtime version is also needed for Scala --- build.sbt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 62ae46db46..931c1fbedd 100644 --- a/build.sbt +++ b/build.sbt @@ -256,7 +256,13 @@ val undocumentedRefs = jsProjects ++ Seq[ProjectReference](benchmarks, example.jvm, tests.jvm, tests.js) lazy val releaseSettings = Seq( - scalacOptions ++= Seq("-release", "8") + scalacOptions ++= { + val version = System.getProperty("java.version") + if (version.startsWith("1.8")) + Seq() + else + Seq("-release", "8") + } ) lazy val root = project From e6ea24efd3b828e89cd47f6176c56b59210fd03a Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Wed, 16 Feb 2022 12:55:46 +0100 Subject: [PATCH 4/7] Add target flag on Scala 2 and comments --- build.sbt | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 931c1fbedd..55dd183c1f 100644 --- a/build.sbt +++ b/build.sbt @@ -258,10 +258,24 @@ val undocumentedRefs = lazy val releaseSettings = Seq( scalacOptions ++= { val version = System.getProperty("java.version") - if (version.startsWith("1.8")) - Seq() - else - Seq("-release", "8") + + // 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) + Seq("-target:8") + else + Seq() + + releaseFlag ++ targetFlag } ) From 88779117ad87cdc3120d5d2d5f568b33d4853ed6 Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Wed, 16 Feb 2022 13:00:07 +0100 Subject: [PATCH 5/7] Guard with Java runtime version again --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 55dd183c1f..6b5b78231e 100644 --- a/build.sbt +++ b/build.sbt @@ -270,7 +270,7 @@ lazy val releaseSettings = Seq( // 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) + if (!isDotty.value && !version.startsWith("1.8")) Seq("-target:8") else Seq() From b95665e88cbac9a213e94f9a7a07bf81a1920e3c Mon Sep 17 00:00:00 2001 From: Vasil Vasilev Date: Fri, 18 Feb 2022 23:48:59 +0100 Subject: [PATCH 6/7] Use the proper option syntax for Scala 2.12 --- build.sbt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 6b5b78231e..9a28ec369f 100644 --- a/build.sbt +++ b/build.sbt @@ -270,10 +270,12 @@ lazy val releaseSettings = Seq( // 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("-target:8") - else + 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 } From 8a4f854d6fe0efec55c5655b3b3d409933ca0640 Mon Sep 17 00:00:00 2001 From: Daniel Spiewak Date: Mon, 21 Feb 2022 13:00:01 -0700 Subject: [PATCH 7/7] Refactored `releaseSettings` into an autoplugin --- build.sbt | 45 --------------------------------------- project/Java8Target.scala | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 45 deletions(-) create mode 100644 project/Java8Target.scala diff --git a/build.sbt b/build.sbt index 9a28ec369f..ad1cf85010 100644 --- a/build.sbt +++ b/build.sbt @@ -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) @@ -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 ) @@ -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 @@ -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 @@ -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) @@ -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. @@ -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"), @@ -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 ) @@ -628,7 +586,6 @@ lazy val example = crossProject(JSPlatform, JVMPlatform) .dependsOn(core) .enablePlugins(NoPublishPlugin) .settings(name := "cats-effect-example") - .settings(releaseSettings) .jsSettings(scalaJSUseMainModuleInitializer := true) /** @@ -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) 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") + }) +}