如何覆盖 sbt 插件的依赖关系? [英] How to override the dependency of an sbt plugin?

查看:42
本文介绍了如何覆盖 sbt 插件的依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个名为 sbt-jumi 的 sbt 插件,它为 Jumi.目前 sbt-jumi 插件依赖于当前的 Jumi 版本.

I've written an sbt plugin called sbt-jumi which implements sbt integration for Jumi. Right now the sbt-jumi plugin depends on the current Jumi release.

这是插件 构建的相关行.sbt:

libraryDependencies += "fi.jumi" % "jumi-launcher" % "0.5.376"

并且插件的 user 会将其添加到他的 project/plugins.sbt 文件中:

And a user of the plugin would add this to his project/plugins.sbt file:

addSbtPlugin("fi.jumi.sbt" % "sbt-jumi" % "0.1.0")

现在假设 Jumi 0.6.400 已发布并且向后兼容.sbt-jumi 插件的用户如何将其配置为使用 Jumi 0.6.400,而无需我发布新版本的插件?

Now let's say that Jumi 0.6.400 is released and it's backward compatible. How can a user of the sbt-jumi plugin configure it to use Jumi 0.6.400, without me having to release a new version of the plugin?

这里是如何在 Maven 中进行. 但是如何在 sbt 中进行呢?

Here is how to do it in Maven. But how to do it in sbt?

推荐答案

覆盖插件的依赖与覆盖普通依赖的方式相同,只是配置必须输入到 project/plugins.sbt.图书馆管理中解释了覆盖依赖关系.总结如下:

Overriding the dependencies of plugins happens the same way as overriding normal dependencies, except that the configuration must be entered into project/plugins.sbt. Overriding dependencies is explained in Library Management. Here is a summary:

如果您希望使用的版本大于,则默认情况下,sbt 将使用较大的版本.您可以更改冲突管理器以更改默认行为 - 例如,这将在冲突时产生错误:

If the version you wish to use is greater than the dependency that you would get transitively, sbt will use the larger version by default. You may change the conflict manager to change the default behavior - for example this will create an error on conflict:

conflictManager := ConflictManager.strict

换句话说,project/plugins.sbt 中的这个可以工作:

In other words, this in project/plugins.sbt would work:

libraryDependencies += "fi.jumi" % "jumi-launcher" % "0.6.400"

你可以使用reload plugins然后show update来检查你的插件依赖.它现在应该将旧版本显示为(EVICTED)".

You may check your plugin dependencies using reload plugins and then show update. It should now show the older version as "(EVICTED)".

如果您希望使用的版本低于默认依赖项,那么您将需要以不同方式覆盖.一种方法是强制依赖:

If the version you wish to use is lower than the default dependency, then you will need to override differently. One way is to force the dependency:

libraryDependencies += "fi.jumi" % "jumi-launcher" % "0.4.350" force()

另一种方法是使用 dependencyOverrides 设置:

Another way is to use the dependencyOverrides setting:

dependencyOverrides += "fi.jumi" % "jumi-launcher" % "0.4.350"

这两种方法的区别在于覆盖不会引入直接依赖.我认为插件的区别并不重要,但对于已发布的工件,它具有 一些差异.

The difference between the two methods is that overriding doesn't introduce a direct dependency. I don't think the difference matters for plugins, but for published artifacts it has some differences.

这篇关于如何覆盖 sbt 插件的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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