在 sbt 中,如何与一个版本中不需要的依赖项交叉构建? [英] In sbt, how can I cross-build with dependencies that are not required in one version?

查看:34
本文介绍了在 sbt 中,如何与一个版本中不需要的依赖项交叉构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Scala 2.10 和 2.11(最终也是 2.12)交叉构建一个项目.一些属于 2.10 的包,例如解析器组合器,在 2.11 中独立打包.因此,它们不需要在 2.10 版本中提及,但在 2.11 中需要.此外,可能有多个这样的包,需要使用一个通用版本.

I need to cross-build a project with both Scala 2.10 and 2.11 (and ultimately 2.12 also). Some packages that were part of 2.10, for example parser-combinators, are packaged independently in 2.11. Thus they are not required to be mentioned in the 2.10 build but are required in 2.11. Furthermore, there may be more than one such package, which are required to use a common version.

我在 SBT 网站上找到了 文档 re:cross-building 在这里有点缺乏帮助.而且,虽然有几个 StackOverflow Q&As 与这个主题相关,但我找不到一个解决这个特定问题的问题.

I found the documentation re: cross-building on the SBT site to be somewhat lacking in helpfulness here. And, although, there are several StackOverflow Q&As which relate to this subject, I could not find one that addressed this specific point.

推荐答案

解决方案如下(只显示build.sbt的相关部分):

The solution is as follows (showing only the relevant part of build.sbt):

scalaVersion := "2.10.6"
crossScalaVersions := Seq("2.10.6","2.11.8")

val scalaModules = "org.scala-lang.modules"
val scalaModulesVersion = "1.0.4"

val akkaGroup = "com.typesafe.akka"
lazy val akkaVersion = SettingKey[String]("akkaVersion")
lazy val scalaTestVersion = SettingKey[String]("scalaTestVersion")

akkaVersion := (scalaBinaryVersion.value match {
  case "2.10" => "2.3.15"
  case "2.11" => "2.4.1"
})
scalaTestVersion := (scalaBinaryVersion.value match {
  case "2.10" => "2.2.6"
  case "2.11" => "3.0.1"
})

libraryDependencies ++= (scalaBinaryVersion.value match {
  case "2.11" => Seq(
    scalaModules %% "scala-parser-combinators" % scalaModulesVersion,
    scalaModules %% "scala-xml" % scalaModulesVersion,
    "com.typesafe.scala-logging" %% "scala-logging" % "3.4.0"
  )
  case _ => Seq()
}
)

libraryDependencies ++= Seq(
  akkaGroup %% "akka-actor" % akkaVersion.value % "test",
  "org.scalatest" %% "scalatest" % scalaTestVersion.value % "test"
)

请注意,此解决方案还解决了如何根据二进制版本设置依赖项的版本的问题.我认为这可能会在 Stackoverflow 的其他地方解决,但在这里都在同一个地方.

Note that this solution also addresses the problem of how to set the version of a dependency(ies) according to the binary version. I think this may be addressed elsewhere in Stackoverflow but here it is all in the same place.

这篇关于在 sbt 中,如何与一个版本中不需要的依赖项交叉构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆