26

If I want to add a plugin that's in a local directory outside the project tree, what's the right way to do that? Say I clone something simple like https://github.com/steppenwells/sbt-sh.git to /tmp/sbt-sh - what do I put in my build.sbt file to use the plugin from /tmp/sbt-sh that will pick up any changes I make in /tmp/sbt-sh?

James Moore
  • 8,636
  • 5
  • 71
  • 90

2 Answers2

18

Something like this in project/project/Build.scala should do it:

import sbt._
object PluginDef extends Build {
    lazy val projects = Seq(root)
    lazy val root = Project("plugins", file(".")) dependsOn( shPlugin )
    lazy val shPlugin = uri("file:///tmp/sbt-sh")
}

Note that that the doubly-nested project directories are required. I'm not aware of any way to do this from an .sbt file (there may be a way, but I don't know what it is).

This is documented here (see "1d) Project dependency").

James Moore
  • 8,636
  • 5
  • 71
  • 90
Paul Butcher
  • 10,722
  • 3
  • 40
  • 44
  • 2
    Thanks. I saw that but it didn't occur to me that you could just use a file:// url. Seems like there should be a more straightforward way to do this though, something like addLocalSbtPlugin("/tmp/sbtsh") – James Moore Dec 20 '11 at 00:51
  • 2
    This might work too (I've not tried it): lazy val shPlugin = file("/tmp/sbt-sh") – Paul Butcher Dec 20 '11 at 00:55
  • 2
    Also, the error message you get if you put in the wrong filename is a bit misleading: Invalid build URI (no handler available): file:///tmp/sbt-shX/ (where sbt-shX doesn't exist) – James Moore Dec 20 '11 at 01:09
  • 1
    And yes, your file() suggestion works: lazy val webPlugin = file("/tmp/sbt-sh") – James Moore Dec 20 '11 at 01:11
13

In 0.13, there's a) a simple way to do this, and b) better documentation. @PaulButcher's answer pointed to section 1d of the sbt documentation for plugins, which now tells you to edit project/plugins.sbt:

Up to 0.13.0:

(@axel22 points out this has changed, so check the current doc before you copy this)

lazy val root = project.in( file(".") ).dependsOn( assemblyPlugin )
lazy val assemblyPlugin = uri("git://github.com/sbt/sbt-assembly#0.9.1")

And of course that uri(... can be replaced with a file("/tmp/sbt-sh").

Update:

After sbt 0.13.0 you'll need to wrap the uri or file with RootProject. I.e.,

lazy val root = project.in( file(".") ).dependsOn( assemblyPlugin )
lazy val assemblyPlugin = RootProject(file("lib/sbt-sh"))
Shon
  • 3,989
  • 1
  • 22
  • 35
James Moore
  • 8,636
  • 5
  • 71
  • 90