How to override the dependency of an sbt plugin?

守給你的承諾、 提交于 2019-12-18 01:53:50

问题


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.

Here is the relevant line from the plugin's build.sbt:

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

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

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

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?

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


回答1:


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

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

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

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

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.



来源:https://stackoverflow.com/questions/18065982/how-to-override-the-dependency-of-an-sbt-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!