Alon
Alon

Reputation: 11885

How to handle dependencies of projects with different Scala versions?

I have three Scala projects:

Project A - must have version 2.11.9 of Scala.

Project B - must have version 2.12.13 of Scala.

Common - the version does not matter.

Both Projects A and B use Common.

Is there any way to make it work other than compiling two times the Common project, with two different versions?

And if it's the only option, how can I manage it in the easiest way? Because going from one version to another in build.sbt means also to change the versions of many dependencies, and it is a mess.

Upvotes: 2

Views: 749

Answers (1)

Gaël J
Gaël J

Reputation: 15050

Like said in a comment, you want to use what is called "cross building" for your "common" project so that it's built and published for both Scala 2.11 and Scala 2.12.

SBT support this natively.

If later you have a more complex project structure you can have a look to an useful plugin called project-matrix for cross building by generating a SBT subproject for each Scala version (or actually other dimensions like JVM/JavaScript).

As for dependencies, you should be using the %% operator when defining dependencies so that the appropriate Scala version of the dependency is picked up automatically.

Upvotes: 2

Related Questions