如何为Play 2.3开发sbt插件?

时间:2014-06-10 02:06:05

标签: playframework sbt playframework-2.3

有人可以帮助我让play-plovr-plugin工作吗?它似乎没有被触发。我在插件中有以下代码,但我似乎无法从我的Play 2.3项目中触发插件:

override def projectSettings: Seq[Setting[_]] =
    inConfig(Assets)(basePlovrSettings) ++
    inConfig(TestAssets)(basePlovrSettings) ++
    Seq(
      plovr in Assets := (plovr in Assets).dependsOn(WebKeys.webModules in Assets).value,
      plovr in TestAssets := (plovr in TestAssets).dependsOn(WebKeys.webModules in TestAssets).value
    )

1 个答案:

答案 0 :(得分:2)

首先,您的插件已激活。您可以通过执行about来检查它,其中列出了所有插件。其中有你的插件。

[info] Available Plugins: ... com.benmccann.playplovr.PlayPlovrPlugin...

这意味着您可以通过web-assets:plovr执行此操作。

然而,正如您所提到的,您希望通过编译方式执行它。您可以说您的任务是由编译触发的。

projectSettings添加

plovr in Assets <<= (plovr in Assets).triggeredBy(compile in Compile)

e.g。

override def projectSettings: Seq[Setting[_]] =
    inConfig(Assets)(basePlovrSettings) ++
    inConfig(TestAssets)(basePlovrSettings) ++
    Seq(
      plovr in Assets := (plovr in Assets).dependsOn(WebKeys.webModules in Assets).value,
      plovr in TestAssets := (plovr in TestAssets).dependsOn(WebKeys.webModules in TestAssets).value,
      plovr in Assets <<= (plovr in Assets).triggeredBy(compile in Compile)
    )

总结一下,

  override def requires = SbtWeb

  override def trigger = AllRequirements

将激活您的插件(如您在about中所见)并添加其设置,但您必须告诉它您想要的设置。 You could read interesting article, which should explain it.