2

I am creating a plugin for my organization that provides a framework to quickly create new services. As part of this there are several plugins that all projects should have. While I could just create a template for this and create each new application from that, I would rather create a plugin. This plugin will provide a base set of functionality as well as include a bunch of other plugins.

In this fashion, the end-user only has to update one plugin when they want to upgrade their stack. It's less flexible, but it's also a lot easier to manage. I started writing my plugin, and the first thing I want to do is tie the Play plugin into the project. However I can't seem to get it to work. I tried adding the Play sbt-plugin to my plugins.sbt withing the plugin, but it doesn't allow me to access the play.Play.autoLoader._ namespace within the plugins application code. For example:

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)
  }
}
Michael Zajac
  • 55,144
  • 7
  • 113
  • 138
  • These guys are doing similar work in production with SBT autoplugins: https://github.com/allenai/sbt-plugins they did a presentation about it at PNWScala a few weeks ago. It requires at least SBT 0.13.5 – Gangstead Dec 09 '14 at 18:24
  • Will definitely check it out thanks. I was looking at the `sbt-plugin` that Play uses and it seems to do what I'm talking about with the native-packager, but I can't seem to get the packages to resolve properly. –  Dec 09 '14 at 18:54
  • @Gangstead - I ended up using auto-plugins to solve my problem. If you could create an answer response, I would be glad to accept it. –  Dec 10 '14 at 13:45

1 Answers1

3

You can import project settings and configuration into SBT with auto plugins: http://www.scala-sbt.org/release/api/index.html#sbt.AutoPlugin

This was introduced in SBT 0.13.5

Examples of Autoplugins being used in production: http://github.com/allenai/sbt-plugins They did a presentation about it at PNWScala a few weeks ago. It requires at least SBT 0.13.5

Gangstead
  • 4,152
  • 22
  • 35