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

查看:193
本文介绍了如何重写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:

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

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天全站免登陆