Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In sbt, how do you add a plugin that's in the local filesystem?

Tags:

scala

sbt

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?

like image 525
James Moore Avatar asked Dec 19 '11 23:12

James Moore


People also ask

Where are sbt plugins stored?

Plugins can be installed for all your projects at once by dropping them in ~/. sbt/plugins/. ~/. sbt/plugins/ is an sbt project whose classpath is exported to all sbt build definition projects.

What is plugins sbt file?

sbt/1.0/plugins/ is an sbt project whose classpath is exported to all sbt build definition projects. Roughly speaking, any . sbt or . scala files in $HOME/. sbt/1.0/plugins/ behave as if they were in the project/ directory for all projects.


2 Answers

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").

like image 154
Paul Butcher Avatar answered Oct 22 '22 12:10

Paul Butcher


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"))
like image 24
James Moore Avatar answered Oct 22 '22 12:10

James Moore