SBT: Cross build project for two Scala versions with different dependencies

こ雲淡風輕ζ 提交于 2020-05-15 02:39:26

问题


I have the following use case. I would like to build the same Scala project for scala 2.10 and 2.12. When doing so I would like to specify some of the dependencies for the 2.10 version as provided whereas I'd like to have those compiled in the jar for 2.12.

I was looking at SBT's docs and found how I can split a build.sbt into separate declarations but those always get mentioned as sub-modules. In my case I'd like to cross-build the whole app - not specific parts of it.

Any hints or resources will be appreciated.


回答1:


You can assemble the libraryDependencies depending on the Scala version. Simplified example, may not build..:

libraryDependencies := {
  CrossVersion.partialVersion(scalaVersion.value) match {
    case Some((2, scalaMajor)) if scalaMajor == 12 =>
      libraryDependencies.value ++ Seq(
        "your.org" %% "your-lib" % "1.0")
    case Some((2, scalaMajor)) if scalaMajor == 10 =>
      libraryDependencies.value ++ Seq(
        "your.org" %% "your-lib" % "1.0" % provided)
    case _ => Seq()
  }
}

For a full example, see http://github.com/scala/scala-module-dependency-sample



来源:https://stackoverflow.com/questions/44738773/sbt-cross-build-project-for-two-scala-versions-with-different-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!