SBT Plugin that adds Plugins

492 views Asked by At

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)
  }
}
1

There are 1 answers

0
Gangstead On BEST ANSWER

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