基于 scalaVersion 的条件 addSbtPlugin [英] Conditional addSbtPlugin based on scalaVersion

查看:36
本文介绍了基于 scalaVersion 的条件 addSbtPlugin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个仅适用于 Scala 2.11 的插件 (sbt-scapegoat).

I'm using a plugin (sbt-scapegoat) which only works for Scala 2.11.

我可以有一个基于 scalaVersion 的条件 addSbtPlugin 吗?喜欢:

Can I have a conditional addSbtPlugin based on scalaVersion? Like:

if (scalaVersion.value.startsWith("2.11")) addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "0.94.6")

我怎样才能在 SBT 中做到这一点?

How can I do this in SBT?

简氏

推荐答案

tl;dr 根据问题的描述,这是不可能的.

tl;dr It's not possible given the description of the problem.

至少一个 sbt 项目涉及两个构建配置——真正的项目(你想把钱押在上面)和用于构建项目的元构建.是的,我知道这听起来有点奇怪,但恕我直言,这是一个非常强大的概念.

There are at least two build configurations involved in a sbt project - the real project (you want to bet your money on) and the meta build for the build of your project. Yes, I know it sounds a little weird, but it's a very powerful concept IMHO.

参见 sbt 是递归的:

项目目录是您构建中的另一个构建,它知道如何构建您的构建.为了区分构建,我们有时使用术语正确构建来指代您的构建,而使用元构建来指代项目中的构建.元构建中的项目可以做任何其他项目可以做的事情.您的构建定义是一个 sbt 项目.

The project directory is another build inside your build, which knows how to build your build. To distinguish the builds, we sometimes use the term proper build to refer to your build, and meta-build to refer to the build in project. The projects inside the metabuild can do anything any other project can do. Your build definition is an sbt project.

sbt 在 Scala 上运行并且需要它的严格版本.没有办法改变它,除非你想把时间花在你一开始就不应该接触的事情上:)

sbt runs atop Scala and requires a strict version of it. No way to change it unless you fancy spending time on things you should really not be touching in the first place :)

你可以做的是在project/plugins.sbt中应用插件,然后在项目中,根据插件的设置>scalaVersion 项目构建的不是元构建本身.

What you can do is to apply the plugin in project/plugins.sbt and then, in the project, apply the settings of the plugin selectively, per scalaVersion of the project's build not the meta-build's itself.

答案并没有那么复杂,但是解释简单的概念对我来说通常不是一件容易的事.玩得开心!如果使用得当,它会很快给你回报.

It's not that complicated as the answer reads, but explaining simple concepts is usually not an easy task for me. Have fun with sbt! It's gonna pay you back very soon when used properly.

这篇关于基于 scalaVersion 的条件 addSbtPlugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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