I have a library that needs two different versions of "com.thesamet.scalapb" %% "compilerplugin"
depending on the Scala version.
In my project/scalapb.sbt
I have this code:
def scalapbVersion(version:String): String =
if(version == "2.11") {
println(s">>>>>>>> Using 0.9.7 to fix 2.11 compat. ${version}")
"0.9.7"
} else {
println(s">>>>>>>> Using last version. ${version}")
"0.10.2"
}
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % scalapbVersion(scalaBinaryVersion.value)
Executing sbt clean "++2.11.12 compile
I get >>>>>>>> Using lastest version. 2.12
but in the logs, also, I can see that the cross-build plugin changes the version to Scala 2.11 after the previous message:
[info] Setting Scala version to 2.11.12 on 13 projects.
[info] Excluded 1 projects, run ++ 2.11.12 -v for more details.
So I suppose that the order is:
How to integrate sbt-protoc
with sbt cross-build?
sbt files in the project
directory are evaluated before a specific scala version is picked up for cross building. This is why passing ++2.11.12
has no effect on scalaBinaryVersion
in the context of project/scalapb.sbt
.
Using different versions of compilerplugin in a single build is not officially supported at this point, but there are a few workarounds that you can try:
libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime" % (if (scalaVersion.value == "2.12.10") "0.10.8" else "0.9.7")
Use 0.9.7 for all scala versions.
If it's reasonable for your situation, consider dropping Scala 2.11 support as Scala 2.11 reached end-of-life a few years ago.