在sbt中,如何使用一个版本中不需要的依赖项进行交叉构建?(In sbt, how can I cross

编程入门 行业动态 更新时间:2024-10-27 03:33:29
在sbt中,如何使用一个版本中不需要的依赖项进行交叉构建?(In sbt, how can I cross-build with dependencies that are not required in one version?)

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

我发现文档是:在SBT网站上交叉构建在这里有点缺乏帮助。 而且,虽然有几个与此主题相关的StackOverflow Q&As,但我找不到解决这一特定问题的问题。

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.

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的相关部分):

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的其他地方解决,但在这里它们都在同一个地方。

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" )

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.

更多推荐

本文发布于:2023-07-18 11:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1159805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   中不   版本   sbt   cross

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!