2

In a multiproject build, I have two projects, A and B, that are cross-compiled to Scala 2.12 and Scala 2.13. I would like to add a task to project A that depends on B's Scala 2.12 classpath (B / Compile / fullClasspath) regardless of the scala version used in A:

ThisBuild / scalaVersion := "2.13.2"
ThisBuild / crossScalaVersions := Seq("2.13.2", "2.12.10")

val foo = taskKey[Unit]("foo-task")

lazy val B = project.in(file("B"))

lazy val A = project.in(file("A")).settings(
  foo := {
    println((B / Compile / fullClasspath).value)
  }
)

As is, running A/foo would print the B's scala-2.13 classpath. How can this be changed so that B's Scala 2.12 classpath is printed?

Context: during source generation for A, I would like to execute code from B inside SBT, so I needed the 2.12 classes of B, regardless of the version of A being compiled.

thesamet
  • 6,382
  • 2
  • 31
  • 42
  • 1
    Could this help? https://stackoverflow.com/questions/28402198/sbt-scala-cross-versions-with-aggregation-and-dependencies – ekrich Jun 24 '20 at 17:04

1 Answers1

2

You can use sbt-cross instead of crossScalaVersions, then you'll have a separate subproject for each scala version.

https://github.com/lucidsoftware/sbt-cross

Matthias Berndt
  • 4,387
  • 1
  • 11
  • 25