加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 在另一个SBT插件中显式启用SBT插件

发布时间:2020-12-16 19:14:20 所属栏目:安全 来源:网络整理
导读:我正在编写一个sbt插件来抽象出一些涉及我使用的常见插件的样板.在这个任务中,one of the plugin我正在尝试配置它需要设置为noTrigger,这需要在项目设置中明确启用插件. 使用SBT AutoPlugin,如果我设置requires = BuildInfoPlugin和trigger = allRequirement
我正在编写一个sbt插件来抽象出一些涉及我使用的常见插件的样板.在这个任务中,one of the plugin我正在尝试配置它需要设置为noTrigger,这需要在项目设置中明确启用插件.

使用SBT AutoPlugin,如果我设置requires = BuildInfoPlugin和trigger = allRequirements,那么如果我明确启用基本插件,设置将自动加载,或者如果我设置上述需求并触发= 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
}

.

/* 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,但是想知道是否有更清洁/更首选的方法.

解决方法

不比推导更优雅,但可能更灵活:

object DerivedPlugin extends AutoPlugin {

  override def trigger: PluginTrigger = allRequirements
  override def requires = JvmPlugin

  val autoImport = BasePlugin.autoImport

  override lazy val projectSettings = BasePlugin.projectSettings

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读