【问题标题】:Explicitly enable SBT plugin inside another SBT plugin在另一个 SBT 插件中显式启用 SBT 插件
【发布时间】:2015-08-23 03:18:37
【问题描述】:

我正在编写一个 sbt 插件来抽象出一些与我使用的一些常见插件相关的样板。在此任务中,我尝试配置的 one of the plugin 将其 requires 设置为 noTrigger,这需要在项目设置中显式启用插件。

使用 SBT AutoPlugin,如果我设置了 requires = BuildInfoPlugintrigger = allRequirements,那么如果我明确启用基本插件,或者如果我设置了上述要求和 trigger = noTrigger,那么设置将自动加载,然后明确添加我正在工作的插件on 也会导入基础插件。

/* 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
}

.

/* Requires enablePlugins(BuildInformation) to be explicitly set on project,
   which will automatically import BuildInfoPlugin */
object BuildInformation extends AutoPlugin {

  override def requires = BuildInfoPlugin
}

有没有办法让衍生插件显式导入基础插件,而不需要显式添加衍生插件本身? (例如,来自 PlayFramework 的 PlayScala 插件会在加载时引入 sbt-native-packager,但需要显式启用 PlayScala)

我想到的一件事就是扩展基本插件,并将其触发器方法覆盖为allRequirements,但想知道是否有更清洁/更首选的方法。

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    并不比派生更优雅,但可能更灵活:

    object DerivedPlugin extends AutoPlugin {
    
      override def trigger: PluginTrigger = allRequirements
      override def requires = JvmPlugin
    
      val autoImport = BasePlugin.autoImport
    
      override lazy val projectSettings = BasePlugin.projectSettings
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-04
      • 2012-07-21
      • 2015-01-12
      • 2019-10-24
      • 2015-04-30
      • 2016-07-27
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多