【问题标题】:SBT Plugin that adds Plugins添加插件的 SBT 插件
【发布时间】:2015-02-07 16:20:06
【问题描述】:

我正在为我的组织创建一个插件,它提供了一个快速创建新服务的框架。作为其中的一部分,所有项目都应该有几个插件。虽然我可以为此创建一个模板并从中创建每个新应用程序,但我宁愿创建一个插件。该插件将提供一组基本功能,并包含许多其他插件。

以这种方式,最终用户只需要在他们想要升级他们的堆栈时更新一个插件。它不太灵活,但也更容易管理。我开始编写我的插件,我想做的第一件事就是将 Play 插件绑定到项目中。但是我似乎无法让它工作。我尝试使用插件将 Play sbt-plugin 添加到我的 plugins.sbt 中,但它不允许我访问插件应用程序代码中的 play.Play.autoLoader._ 命名空间。例如:

project/plugins.sbt

resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.6")

src/main/scala/com/example/sbt/plugin/Plugin.scala

package com.example.sbt.plugin

import sbt._                     // works just fine
import play.Play.autoImport._    // error, path doesn't exist

object Plugin {

  def project(settings: Seq[Def.Setting[_] /* other params */) : Project = {
    Project(settings).enablePlugins(play.PlayScala)
  }
}

【问题讨论】:

  • 这些人正在使用 SBT 自动插件在生产中做类似的工作:github.com/allenai/sbt-plugins 几周前他们在 PNWScala 上做了一个演示。它至少需要 SBT 0.13.5
  • 一定会去看看谢谢。我正在查看 Play 使用的 sbt-plugin,它似乎与我所说的原生打包程序一样,但我似乎无法正确解析这些包。
  • @Gangstead - 我最终使用自动插件来解决我的问题。如果您可以创建一个答案响应,我会很高兴接受它。

标签: scala playframework-2.0 sbt sbt-plugin


【解决方案1】:

您可以使用自动插件将项目设置和配置导入 SBT:http://www.scala-sbt.org/release/api/index.html#sbt.AutoPlugin

这是在 SBT 0.13.5 中引入的

生产中使用的自动插件示例:http://github.com/allenai/sbt-plugins 几周前,他们在 PNWScala 上做了一个关于它的演讲。它至少需要 SBT 0.13.5

【讨论】:

    猜你喜欢
    • 2013-01-19
    • 2015-08-24
    • 2016-07-27
    • 2017-07-04
    • 2016-02-07
    • 2021-07-21
    • 2013-01-20
    • 2021-07-11
    • 2011-05-16
    相关资源
    最近更新 更多