Cross compiling Scala versions with differing project modules

Viewed 134

I'm trying to use sbt-projectmatrix to cross compile scala versions. However, I want one of the final modules to use different internal dependencies, based on the target Scala version.

This is a toy example of where I am right now:

lazy val root: Project = (projectMatrix in file("."))
  .settings(commonSettings: _*)
  .settings(publish := {})
  .aggregate(
    a_spark21.projectRefs ++
    a_spark22.projectRefs ++
    a_spark23.projectRefs ++
    a_spark24.projectRefs ++
    top.projectRefs ++: _*
  )

lazy val top: Project = (projectMatrix in file("vulcan-hive"))
  .disablePlugins(SitePreviewPlugin, SitePlugin, ParadoxPlugin, ParadoxSitePlugin)
  .settings(name := "vulcan-hive")
  .settings(commonSettings: _*)
  .jvmPlatform(scalaVersions = Seq(versions.scala211, versions.scala212))
  .customRow(
    scalaVersions = Seq(versions.scala211),
    axisValues = Seq(VirtualAxis.jvm),
    _.settings(
      SubModuleDependencies.hiveDependencies24,
      libraryDependencies ++= Dependencies.Spark24.Compile.all.map(_.force()),
    )
  )
  .customRow(
    scalaVersions = Seq(versions.scala212),
    axisValues = Seq(VirtualAxis.jvm),
    _.settings(
      SubModuleDependencies.hiveDependencies24,
      libraryDependencies ++= Dependencies.Spark24.Compile.all.map(_.force()),
    )
  )
  .dependsOn(a_spark24 % "compile->compile;test->test", a_spark23 % "compile->compile;test->test", a_spark22 % "compile->compile;test->test", a_spark21 % "compile->compile;test->test")


lazy val a_spark21: Project = (projectMatrix in file(a_spark21))
  .jvmPlatform(scalaVersions = Seq(versions.scala211))
  .customRow(
    scalaVersions = Seq(versions.scala211),
    axisValues = Seq(VirtualAxis.jvm),
    _.settings(
      libraryDependencies ++= Dependencies.Spark21.Compile.all.map(_.force())
    )
  )

lazy val a_spark22: Project = ...
lazy val a_spark23: Project = ...

lazy val a_spark24: Project = (projectMatrix in file(a_spark24))
  .jvmPlatform(scalaVersions = Seq(versions.scala211, versions.scala212))
  .customRow(
    scalaVersions = Seq(versions.scala211),
    axisValues = Seq(VirtualAxis.jvm),
    _.settings(
      libraryDependencies ++= Dependencies.Spark24.Compile.all.map(_.force())
    )
  )
  .customRow(
    scalaVersions = Seq(versions.scala212),
    axisValues = Seq(VirtualAxis.jvm),
    _.settings(
      libraryDependencies ++= Dependencies.Spark24.Compile.all.map(_.force())
    )
  )

This fails with this error:

no rows were found in a_spark23 matching ProjectRow(true, List(PlatformAxis(jvm,JVM,jvm), ScalaVersionAxis(2.12.12,2.12))): List(ProjectRow(true, List(PlatformAxis(jvm,JVM,jvm), ScalaVersionAxis(2.11.12,2.11))), ProjectRow(true, List(PlatformAxis(jvm,JVM,jvm), ScalaVersionAxis(2.11.12,2.11))))

This error makes sense since top is trying is trying to find 2.12 dependencies for a_spark23 even though a_spark23 doesn’t have a 2.12 row defined. Is there a way to move dependsOn definitions to the customRow arguments? Or access the scalaBinaryVersion in outside the settings closure so that I can pass different lists to dependsOn?

The final product I want is top_2.12 that's depends on a_spark24_2.12 and top_2.11 that depends on [a_spark21_2.11, a_spark22_2.11, a_spark23_2.11, a_spark24_2.11]

Any help or guidance would be greatly appreciated!

0 Answers
Related