manual import of SBT plugin into project

31 views
Skip to first unread message

Peter Becich

unread,
Mar 9, 2015, 1:58:16 PM3/9/15
to ens...@googlegroups.com
For the purpose of building and testing `ensime-sbt`, how do you manually import an SBT plugin, rather than pulling it from Maven?

I've read this documentation without finding an answer:  http://www.scala-sbt.org/0.13.5/docs/Extending/Plugins.html#creating-a-plugin

Specifically in that documentation, I can't figure out from this excerpt how to bring `MyPlugin` into the scope `build.sbt`, where `build.sbt` is a skeleton SBT project to test the new SBT plugin, not the `build.sbt` of the SBT plugin itself.

Plugin.scala

package sbtsample

import sbt._
import Keys._
object Plugin extends AutoPlugin
{
  override lazy val projectSettings = Seq(commands += myCommand)

  lazy val myCommand =
    Command.command("hello") { (state: State) =>
      println("Hi!")
      state
    }
}

This example demonstrates how to take a Command (here, myCommand) and distribute it in a plugin. Note that multiple commands can be included in one plugin (for example, use commands ++= Seq(a,b)). See Commands for defining more useful commands, including ones that accept arguments and affect the execution state.

For a user to consume this plugin, it requires an explicit include via the Project instance. Here's what their local sbt will look like.

build.sbt

val root = Project("example-plugin-usage", file(".")).setPlugins(MyPlugin)

The setPlugins method allows projects to explicitly define the `RootPlugin`s they wish to consume. `AutoPlugin`s are automatically added to the project as appropriate.




Lastly, SBT plugins and Scala plugins are never imported together, right?

Thank you,
  Peter

Sam Halliday

unread,
Mar 9, 2015, 2:22:39 PM3/9/15
to ens...@googlegroups.com

Peter Becich

unread,
Mar 9, 2015, 3:35:40 PM3/9/15
to ens...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages