SBT:具有不同依赖项的两个 Scala 版本的交叉构建项目 [英] SBT: Cross build project for two Scala versions with different dependencies

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

问题描述

我有以下用例.我想为 Scala 2.10 和 2.12 构建相同的 Scala 项目.这样做时,我想为 2.10 版本指定一些依赖项,而我想在 2.12 的 jar 中编译这些依赖项.

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.

我正在查看 SBT 的文档,发现如何将 build.sbt 拆分为单独的声明,但这些声明总是被提及为 子模块.就我而言,我想交叉构建整个应用程序 - 而不是它的特定部分.

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.

推荐答案

您可以根据 Scala 版本组装 libraryDependencies.简化示例,可能无法构建..:

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()
  }
}

有关完整示例,请参阅 http://github.com/scala/scala-模块依赖样本

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

这篇关于SBT:具有不同依赖项的两个 Scala 版本的交叉构建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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