You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2021/11/29 17:42:57 UTC

[daffodil] branch main updated: Add -release 8 to scalac and javac options

This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new bf576e8  Add -release 8 to scalac and javac options
bf576e8 is described below

commit bf576e8be961016df11b2b3caf50e0d8f9616867
Author: Steve Lawrence <sl...@apache.org>
AuthorDate: Mon Nov 29 11:34:36 2021 -0500

    Add -release 8 to scalac and javac options
    
    This ensures that no matter what version of Java you compile Daffodil
    with, Daffodil will always work with Java 8 or newer.
    
    DAFFODIL-2579
---
 build.sbt | 62 ++++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 22 deletions(-)

diff --git a/build.sbt b/build.sbt
index 748fa00..183a33e 100644
--- a/build.sbt
+++ b/build.sbt
@@ -155,26 +155,8 @@ lazy val commonSettings = Seq(
   version := "3.2.0-SNAPSHOT",
   scalaVersion := "2.12.15",
   crossScalaVersions := Seq("2.12.15"),
-  scalacOptions ++= Seq(
-    "-target:jvm-1.8",
-    "-feature",
-    "-deprecation",
-    "-language:experimental.macros",
-    "-unchecked",
-    "-Xfatal-warnings",
-    "-Xxml:-coalescing",
-    "-Xfuture"
-  ),
-  // add scalac options that are version specific
-  scalacOptions ++= scalacCrossOptions(scalaVersion.value),
-  // Workaround issue that some options are valid for javac, not javadoc.
-  // These javacOptions are for code compilation only. (Issue sbt/sbt#355)
-  Compile / compile / javacOptions  ++= Seq(
-    "-source", "8",
-    "-target", "8",
-    "-Werror",
-    "-Xlint:deprecation"
-  ),
+  scalacOptions ++= buildScalacOptions(scalaVersion.value),
+  Compile / compile / javacOptions ++= buildJavacOptions(),
   logBuffered := true,
   transitiveClassifiers := Seq("sources", "javadoc"),
   retrieveManaged := true,
@@ -200,14 +182,50 @@ lazy val commonSettings = Seq(
   testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "--verbosity=1"),
 ) ++ Defaults.itSettings
 
-def scalacCrossOptions(scalaVersion: String) =
-  CrossVersion.partialVersion(scalaVersion) match {
+
+def buildScalacOptions(scalaVersion: String) = {
+  val commonOptions = Seq(
+    "-target:jvm-1.8",
+    "-feature",
+    "-deprecation",
+    "-language:experimental.macros",
+    "-unchecked",
+    "-Xfatal-warnings",
+    "-Xxml:-coalescing",
+    "-Xfuture"
+  )
+
+  val scalaVersionSpecificOptions = CrossVersion.partialVersion(scalaVersion) match {
     case Some((2, 12)) => Seq(
       "-Ywarn-unused:imports"
     )
     case _ => Seq.empty
   }
 
+  val javaVersionSpecificOptions =
+    if (scala.util.Properties.isJavaAtLeast("9"))
+      Seq("-release", "8") // ensure Java backwards compatibility (DAFFODIL-2579)
+    else
+      Seq.empty
+
+    commonOptions ++ scalaVersionSpecificOptions ++ javaVersionSpecificOptions
+}
+
+def buildJavacOptions() = {
+  val commonOptions = Seq(
+    "-Werror",
+    "-Xlint:deprecation"
+  )
+
+  val javaVersionSpecificOptions =
+    if (scala.util.Properties.isJavaAtLeast("9"))
+      Seq("--release", "8") // ensure Java backwards compatibility (DAFFODIL-2579)
+    else
+      Seq.empty
+
+  commonOptions ++ javaVersionSpecificOptions
+}
+
 lazy val nopublish = Seq(
   publish := {},
   publishLocal := {},