Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT Plugin in an unmanaged jar file

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!

like image 947
sshmsh Avatar asked Dec 15 '15 22:12

sshmsh


People also ask

Where are sbt jars stored?

All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.

Which is the correct way to add dependencies in sbt file?

Library dependencies can be added in two ways: unmanaged dependencies are jars dropped into the lib directory. managed dependencies are configured in the build definition and downloaded automatically from repositories.

Does sbt use coursier?

Coursier has been used by SBT for fetching the library dependencies since 1.3. 0.

Does sbt use ivy?

By default, sbt uses the standard Ivy home directory location ${user.


1 Answers

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")
like image 138
0__ Avatar answered Sep 19 '22 08:09

0__