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-sbt.git
The following commit(s) were added to refs/heads/main by this push:
new 6d5f013 Ensure plugins are build with correct JDK compatability
6d5f013 is described below
commit 6d5f013eae6348c365209780599acca168e5c69b
Author: Steve Lawrence <[email protected]>
AuthorDate: Fri Oct 3 14:34:27 2025 -0400
Ensure plugins are build with correct JDK compatability
When building plugins, we want class files to have compatability for the
minimum JDK version supported by the target daffodilVersion. This means
plugins compiled with daffodilVersion 4.0.0+ will have class versions
compatible with JDK 17+. All other daffodilVersions will target JDK 8.
Closes #129
---
.../scala/org/apache/daffodil/DaffodilPlugin.scala | 46 ++++++++++++++++++++++
.../sbt-daffodil/cross-versions-03/build.sbt | 2 +-
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index 4b6cb87..823b9c8 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -359,6 +359,52 @@ object DaffodilPlugin extends AutoPlugin {
}
},
+ /**
+ * If we are building plugins, we want to make sure they are built with
compatability for
+ * the minimum version of Java that daffodilVersion supports, regardless
of the javac
+ * version used for compilation. For example, even when building on Java
17+, we want to
+ * make sure plugins that are built for Daffodil 3.10.0 are built with
Java 8 compatability.
+ * We use daffodilVerison to determine the target JDK version, and the
current javac version
+ * to figure out the right javacOptions to set.
+ */
+ javacOptions ++= {
+ if (daffodilBuildsPlugin.value) {
+ val daffodilPluginJdkCompatMap = Map(
+ ">=4.0.0 " -> "17",
+ "<=3.11.0" -> "8"
+ )
+ val jdkCompat = filterVersions(daffodilVersion.value,
daffodilPluginJdkCompatMap).head
+ val javacOptionsMap = Map(
+ ">=9" -> Seq("--release", jdkCompat),
+ " =8" -> Seq("-source", jdkCompat, "-target", jdkCompat)
+ )
+ filterVersions(Properties.javaSpecVersion, javacOptionsMap).head
+ } else {
+ Seq()
+ }
+ },
+
+ /**
+ * See javacOptions above for details
+ */
+ scalacOptions ++= {
+ if (daffodilBuildsPlugin.value) {
+ val daffodilPluginJdkCompatMap = Map(
+ ">=4.0.0 " -> "17",
+ "<=3.11.0" -> "8"
+ )
+ val jdkCompat = filterVersions(daffodilVersion.value,
daffodilPluginJdkCompatMap).head
+ val scalacOptionsMap = Map(
+ ">=2.13 " -> Seq("--release", jdkCompat),
+ ">=2.12.16 <2.13" -> Seq(s"--target:jvm-$jdkCompat"),
+ "<=2.12.15 " -> Seq(s"-target:jvm-1.$jdkCompat")
+ )
+ filterVersions(scalaVersion.value, scalacOptionsMap).head
+ } else {
+ Seq()
+ }
+ },
+
/**
* DFDL schemas are not scala version specific since they just contain
resources, so we
* disable crossPaths so that published jars do not contain a scala
version. However, if a
diff --git a/src/sbt-test/sbt-daffodil/cross-versions-03/build.sbt
b/src/sbt-test/sbt-daffodil/cross-versions-03/build.sbt
index 82d3f7e..aaa0946 100644
--- a/src/sbt-test/sbt-daffodil/cross-versions-03/build.sbt
+++ b/src/sbt-test/sbt-daffodil/cross-versions-03/build.sbt
@@ -25,7 +25,7 @@ val plugin = (project in file("plugin"))
daffodilVersion := "3.10.0",
daffodilBuildsCharset := true,
)
- .daffodilProject(crossDaffodilVersions = Seq("3.11.0"))
+ .daffodilProject(crossDaffodilVersions = Seq("3.1.0", "3.11.0"))
val schema = (project in file("schema"))
.settings(