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


##########
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:
   Yeah, this is a bit confusing, I'll add a comment in the code clarifying 
this.
   
   But to answer your question, because we add `provided` to the dependencies, 
it means we only compile the sbt-daffodil-utils jars with a specific version of 
Daffodil. And we expect something else to put Daffodil jars on the classpath at 
runtime. In this case, that's the DaffodPlugin and the plugin can put whatever 
Daffodil version it's wants on the classpath. The only requirement is that 
whatever jars we put on the classpath have the same classes and methods that 
the jar expects. And because our API doesn't really change, we can actually put 
any version of Daffodil 3.10.0 or older on the classpath with 
sbt-daffodil-utils_2.12 and everything will just work. Java doesn't care that 
it wasn't compiled with the same jar, it just cares that the jars have the same 
class names and functions that sbt-daffodil-utils expects.
   
   The one gotcha is Daffodil 3.9.0 and older do not have the `compileResource` 
function, so if we tried to call that at runtime we would get a 
NoSuchMethodFound exception. That's the purpose of the 
`daffodilInternalApiVersionMapping`--that essentially tells DaffodilSaver to 
use `compileSource` instead of `compileResource` on older version of Daffodil.
   
   So as a rule of thumb, if Daffodil adds a new API method, then we need a new 
daffodilInternalApiVersionMapping for it to be used so it's not used on old 
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