我正在编写一个sbt插件,以抽象出一些涉及我使用的常见插件的样板文件。在此任务中,我one of the plugin尝试配置将requires
设置为noTrigger
,这需要在项目设置中明确启用插件
如果我设置requires = BuildInfoPlugin
和trigger = allRequirements
,则使用SBT AutoPlugin,如果我明确启用基本插件,或者如果我设置上述要求{{1},则设置将自动加载然后显式添加我正在处理的插件也会导入基本插件。
trigger = noTrigger
/* Requires enablePlugins(BuildInfoPlugin) to be explicitly set on project,
then the settings in this plugin will automatically load. */
object BuildInformation extends AutoPlugin {
override def requires = BuildInfoPlugin
override def trigger = allRequirements
}
有没有办法让衍生插件显式导入基本插件,而不需要明确添加派生插件本身? (例如PlayFramework的PlayScala插件会加载sbt-native-packager,但需要显式启用PlayScala)
我想到的一件事就是扩展基础插件,并将其触发方法覆盖为/* Requires enablePlugins(BuildInformation) to be explicitly set on project,
which will automatically import BuildInfoPlugin */
object BuildInformation extends AutoPlugin {
override def requires = BuildInfoPlugin
}
,但是想知道是否有更清洁/更首选的方法。
答案 0 :(得分:0)
不比推导更优雅,但可能更灵活:
object DerivedPlugin extends AutoPlugin {
override def trigger: PluginTrigger = allRequirements
override def requires = JvmPlugin
val autoImport = BasePlugin.autoImport
override lazy val projectSettings = BasePlugin.projectSettings
}