SBT插件如何依赖另一个插件 [英] How can an SBT plugin depend on another plugin
问题描述
我想写一个依赖于另一个插件的插件MyPlugin"("io.spray" %% "sbt-twirl" % "0.6.0").
I want to write a plugin "MyPlugin" that depends on the another plugin ("io.spray" %% "sbt-twirl" % "0.6.0").
仅仅在 libraryDependencies 中添加 sbt-twirl 是行不通的,因为插件使用不同的路径方案发布比标准库.
Simply adding sbt-twirl in libraryDependencies will not work, because plugins get published with a different path scheme than standard libraries.
我也不能将 sbt-twirl 声明为 MyPlugin 的插件依赖项项目,因为 MyPlugin 不直接使用 sbt-twirl,使用 MyPlugin 的项目会间接使用它.
I also cannot declare sbt-twirl as a plugin dependency to MyPlugin project, because MyPlugin does not use the sbt-twirl directly, it is the project using MyPlugin that will indirectly use it.
MyPlugin 提供了一个在 sbt-twirl 之后运行的任务已生成它的源代码(在 sourceManaged 中)并在编译后生成.
MyPlugin provides a task that is meant to be run after sbt-twirl has generated it's sources (in sourceManaged) and after compilation.
一个简单但不理想的解决方案是要求项目使用MyPlugin 也将 sbt-twirl 声明为插件依赖项,但它不是DRY 因为这两个插件将共享一些设置(目录、版本等),而且它们必须重复和兼容.
A simple but non ideal solution would be to require the project using MyPlugin to also declare sbt-twirl as a plugin dependency, but it is not DRY because the two plugins will be sharing some settings (directories, versions, etc), and they will have to be repeated and compatible.
推荐答案
应该和使用插件作为插件的定义一样,只是在build.sbt
或者project/Build.scala
而不是 project/plugins.sbt
:
It should be the same definition as for using a plugin as a plugin, except that it goes in build.sbt
or project/Build.scala
instead of project/plugins.sbt
:
addSbtPlugin("io.spray" % "sbt-twirl" % "0.6.0")
这篇关于SBT插件如何依赖另一个插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!