stevedlawrence commented on code in PR #136:
URL: https://github.com/apache/daffodil-sbt/pull/136#discussion_r2518580035


##########
build.sbt:
##########
@@ -15,53 +15,115 @@
  * limitations under the License.
  */
 
-name := "sbt-daffodil"
-
-organization := "org.apache.daffodil"
-
-version := IO.read((ThisBuild / baseDirectory).value / "VERSION").trim
-
-scalaVersion := "2.12.19"
-
-scalacOptions ++= Seq(
-  "-Ywarn-unused:imports"
+val commonSettings = Seq(
+  organization := "org.apache.daffodil",
+  version := IO.read((ThisBuild / baseDirectory).value / "VERSION").trim,
+  scalacOptions ++= {
+    scalaBinaryVersion.value match {
+      case "2.12" | "2.13" =>
+        Seq(
+          "-Werror",
+          "-Ywarn-unused:imports"
+        )
+      case "3" =>
+        Seq(
+          "-no-indent",
+          "-Werror",
+          "-Wunused:imports"
+        )
+    }
+  },
+  scmInfo := Some(
+    ScmInfo(
+      browseUrl = url("https://github.com/apache/daffodil-sbt";),
+      connection = "scm:git:https://github.com/apache/daffodil-sbt";
+    )
+  ),
+  licenses := Seq(License.Apache2),
+  homepage := Some(url("https://daffodil.apache.org";)),
+  releaseNotesURL := 
Some(url(s"https://daffodil.apache.org/sbt/${version.value}/";))
 )
 
-scmInfo := Some(
-  ScmInfo(
-    browseUrl = url("https://github.com/apache/daffodil-sbt";),
-    connection = "scm:git:https://github.com/apache/daffodil-sbt";
+lazy val plugin = (project in file("."))
+  .settings(commonSettings)
+  .settings(
+    name := "sbt-daffodil",
+
+    // SBT plugin settings
+    scalaVersion := "2.12.19",
+    crossSbtVersions := Seq("1.8.0"),
+    scriptedLaunchOpts ++= Seq(
+      "-Xmx1024M",
+      "-Dplugin.version=" + version.value
+    ),
+    scriptedDependencies := {
+      // scripted runs publishLocal for the plugin and its dependencies as 
part of the
+      // scriptedDependencies task. But the utils subprojects aren't actually 
dependencies (so
+      // won't be locally published). We still need the util jars locally 
published so the
+      // scripted tests can find the jars at runtime, so we manually run 
publishLocal for each
+      // of the utils subprojects as part of the scriptedDependencies task
+      publishLocal.all(ScopeFilter(projects = inProjects(utils.projectRefs: 
_*))).value
+      scriptedDependencies.value
+    },
+    Test / test := {
+      // run all scripted tasks as part of testing
+      (Compile / scripted).toTask("").value
+      (Test / test).value
+    },
+
+    // Rat check settings
+    ratExcludes := Seq(
+      file(".git"),
+      file("VERSION")
+    ),
+    ratFailBinaries := true
   )
-)
-
-licenses := Seq(License.Apache2)
-
-homepage := Some(url("https://daffodil.apache.org";))
-
-releaseNotesURL := 
Some(url(s"https://daffodil.apache.org/sbt/${version.value}/";))
-
-// SBT Plugin settings
-
-enablePlugins(SbtPlugin)
+  .enablePlugins(SbtPlugin)
+  .aggregate(utils.projectRefs: _*)
 
-crossSbtVersions := Seq("1.8.0")
-
-scriptedLaunchOpts ++= Seq(
-  "-Xmx1024M",
-  "-Dplugin.version=" + version.value
-)
-
-// Rat check settings
-
-ratExcludes := Seq(
-  file(".git"),
-  file("VERSION")
-)
-
-ratFailBinaries := true
-
-Test / test := {
-  // run all scripted tasks as part of testing
-  (Compile / scripted).toTask("").value
-  (Test / test).value
-}
+lazy val utils = (projectMatrix in file("utils"))
+  .settings(commonSettings)
+  .settings(
+    name := "sbt-daffodil-utils"
+  )
+  .settings(
+    javacOptions ++= {
+      scalaBinaryVersion.value match {
+        case "2.12" => Seq("-target", "8")
+        case "2.13" => Seq("-target", "8")
+        case "3" => Seq("-target", "17")
+      }
+    },
+    scalacOptions ++= {
+      scalaBinaryVersion.value match {
+        case "2.12" => Seq(s"--target:jvm-8")
+        case "2.13" => Seq(s"--release", "8")
+        case "3" => Seq(s"--release", "17")
+      }
+    },
+    libraryDependencies ++= {
+      scalaBinaryVersion.value match {
+        case "2.12" => {
+          Seq(
+            // scala-steward:off
+            "org.apache.daffodil" %% "daffodil-japi" % "3.10.0" % "provided",
+            // scala-steward:on
+            "org.scala-lang.modules" %% "scala-collection-compat" % "2.14.0"
+          )
+        }
+        case "2.13" => {
+          Seq(
+            // scala-steward:off
+            "org.apache.daffodil" %% "daffodil-japi" % "3.11.0" % "provided"
+            // scala-steward:on
+          )
+        }
+        case "3" => {
+          Seq(
+            "org.apache.daffodil" %% "daffodil-core" % "4.0.0" % "provided"

Review Comment:
   > I'm not suggesting we do this as part of this change set, but can the 
approach used here be extended to support even older Daffodil versions like 
3.7.0, and even 3.4.0 ?
   
   This approach does support even older versions, but is kindof restricted to 
using APIs that do not have backwards incompatible changes.
   
   For the example above, if Daffodil 3.10.0 had removed `compileSource` and 
replaced it with `compileResource`, then this approach wouldn't work and you 
would have to use reflection. Similarly, if 3.8.0 moves a class to a different 
package, that is a backwards incompatible change and reflection would be 
required.
   
   The way the think about this is we have three jars:
   * sbt-daffodil-utils_2.12 - for 3.10.0 and older
   * sbt-daffodil-utils_2.13 - for 3.11.0
   * sbt-daffodil-tusil_3 - for 4.0.0 and newer
   
   The Daffodil API class must be written to work for all versions within one 
of those ranges. If there are backwards incompatible changes in a range, then 
reflection must be used, likely with classes to abstract away the reflection. 
New APIs can be used, but conditional logic must be used to avoid using the new 
APIs when on older versions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to