5

The requirement: an SBT plugin code is in an unmanaged jar, for example in lib/unmanaged-sbt-plugin-0.0.1.jar. I was expecting the jar file would be picked up by SBT automatically and the plugin would work out-of-the-box, i.e.: the tasks would be accessible from SBT command line, but that is not the case.

The jar file has the sbt/sbt.autoplugins file in it and the plugin works if pulled from a remote repo into the local one and imported via addSbtPlugin(...). Please note I cannot do that - it's a requirement to get it to load from the lib/unmanaged-sbt-plugin-0.0.1.jar and not from the local/remote repo.

Putting the following line in the build.sbt doesn't make the plugin work (there's not error either):

unmanagedJars in Compile += file("lib/unmanaged-sbt-plugin-0.0.1.jar")

The implementation of addSbtPlugin(...) is simply (according to http://www.scala-sbt.org/0.12.2/docs/Getting-Started/Using-Plugins.html):

def addSbtPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =
  libraryDependencies <+= (sbtBinaryVersion in update, scalaBinaryVersion in update) 
  { (sbtV, scalaV) => sbtPluginExtra(dependency, sbtV, scalaV) }

I'm wondering if the above info can be used to resolve my issue?

Thank you in advance!

sshmsh
  • 181
  • 10
  • 1
    Perhaps look at [ModuleID](http://www.scala-sbt.org/0.13.7/api/index.html#sbt.ModuleID). Something like `"my.org" % "my-plugin" % "my-version" from "file:///path/to/jar` might work (not sure - perhaps you need a .pom) – 0__ Dec 16 '15 at 00:02
  • 2
    `unmanagedJars in Compile` - have you tried that _inside the plugins.sbt file in the project directory_? Basically everything in `project` is a meta-project for the base project. – 0__ Dec 16 '15 at 00:03
  • I was able to make it work using this code: `addSbtPlugin("org.my-org" % "unmanaged-sbt-plugin" % "0.0.1" from "file:///./lib/unmanaged-sbt-plugin-0.0.1.jar")`! If you add the answer I'll vote it up, thanks! – sshmsh Dec 16 '15 at 09:48

2 Answers2

7

So you can specify an explicit URL for library dependencies (ModuleID):

addSbtPlugin("org.my-org" % "unmanaged-sbt-plugin" % "0.0.1"
  from "file:///./lib/unmanaged-sbt-plugin-0.0.1.jar")
0__
  • 66,707
  • 21
  • 171
  • 266
1

Have been struggling to get this to work. Could not get it to work with proposed solution using from "file://.." (using sbt 1.0.4).

Got it to work by putting the plugin in project/lib folder and adding all the plugin dependencies to plugins.sbt using libraryDependencies ++= Seq(..) like in build.sbt. You can find the plugin dependencies by looking at the plugin pom file, usually in .ivy2/local/<org>/<pluginname>/poms folder.

Joost den Boer
  • 4,556
  • 4
  • 25
  • 39