1
votes

I would like to compile a project with Scala 2.10 and 2.11 using the sbt cross compile feature. The problem is that this project contains some Flink dependencies. But the Flink jars do not follow the standard binary format (postfixing the name with _2.10 or _2.11): The scala 2.10 jars do not have a postfix and the 2.11 have it.

I found a working solution. But I'm not happy with it and my question is: is there an easier and/or more elegant way to solve this problem?

My current solution:

def flinkDependencies(scalaVersion: String) = {
    if (scalaVersion.startsWith("2.10"))
        Seq(
         "org.apache.flink" % "flink-scala" % flinkVersion % "optional",
         "org.apache.flink" % "flink-streaming-scala" % flinkVersion % "optional"
        )
    else
      Seq(
          "org.apache.flink" %% "flink-scala" % flinkVersion % "optional",
          "org.apache.flink" %% "flink-streaming-scala" % flinkVersion % "optional"
      )
}

libraryDependencies <++= scalaVersion(flinkDependencies)
1
Currently Flink builds with Scala 2.10 by default and does not expose the version number properly. It is planed to fix this in the next release.Matthias J. Sax
@matthias-j-sax That are great news! Thanks. This will make this question obsolete for Flink in the near future. But it would still be interesting to have a nice solution for the current problem.gesundkrank

1 Answers

2
votes

Yes, this is how you would have to do that. A slightly shorter version is this:

libraryDependencies ++= {
  val suffix = if (scalaVersion.value.startsWith("2.11")) "_2.11" else ""
  Seq(
    "org.apache.flink" % s"flink-scala$suffix"           % flinkV % "optional",
    "org.apache.flink" % s"flink-streaming-scala$suffix" % flinkV % "optional"
  )
}