Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use plugin in sbt project when only the plugin's sources available?

Tags:

scala

sbt

I want to use the sbt-scrooge plugin, but its repo is unavailable now - http://koofr.github.com/.

I thought I'd include this plugin's source code directly in my own repo (as a git submodule).

I tried:

git submodule add https://github.com/bancek/sbt-scrooge.git project/sbt-scrooge

and added:

addSbtPlugin("net.koofr" % "sbt-scrooge" % "3.0.45")

to project/plugins.sbt. But it doesn't work - the following exception is thrown:

sbt.ResolveException: unresolved dependency: net.koofr#sbt-scrooge;3.0.45: not found

What's the right way to do that?

I know that I could checkout sbt-scrooge to the local filesystem, then sbt publish-local, and add the local ivy2 repo to sbt as a resolver. But I just want to know whether there are other ways to do this.

like image 934
kuroz Avatar asked Dec 27 '13 04:12

kuroz


2 Answers

As explained here you can puth this in your project/plugins.sbt:

lazy val root = project.in(file(".")).dependsOn(scroogePlugin) 

lazy val scroogePlugin = file("sbt-scrooge") 

Or simply (without creating a local submodule):

lazy val root = project.in(file(".")).dependsOn(scroogePlugin) 

lazy val scroogePlugin = uri("https://github.com/bancek/sbt-scrooge.git") 
like image 99
Nicolas Cortot Avatar answered Sep 22 '22 19:09

Nicolas Cortot


If you want to use a plugin it has to be available to sbt (and somehow finds its place in your local repository so addSbtPlugin can eventually find it or the project (sub)project of your sbt project should have it on the classpath).

Be adviced that not all plugins should be an integral part of a sbt project. Quite the contrary - they can be used in a project, but that doesn't necessarily mean they should be referenced by any project-specific files (within the project's directory), e.g. plugins to generate IDE-specific files. These plugins should be part of the global configuration in ~/.sbt under plugins.

There's also the issue of version mismatch between plugins and sbt. In your case, sbt-scrooge supports 0.12.2 (see project/build.properties) that might be unusable in sbt 0.13+.

With that said, I think the "right way" in your case since the sbt-scrooge plugin seems no longer maintained is to fork the project and maintain yourself in your own repository. sbt 0.13.1 is already the latest version, and the plugin may not yet support it. When the plugin gets new life with your fork other developers might benefit from the resurrection, too and having the sources attached to another project would only hinder reusability.

The answer to a similar question has helped me to offer a working solution that works with sbt 0.12.2 and without cloning the git repository.

$ cat project/build.properties
sbt.version=0.12.2

$ cat project/project/SbtScroogePlugin.scala
import sbt._

object SbtScroogePlugin extends Build {
    lazy val plugins = Project("plugins", file(".")) dependsOn sbtScroogePlugin
    lazy val sbtScroogePlugin = uri("https://github.com/bancek/sbt-scrooge.git")
}

$ cat sbt-scrooge.sbt
import net.koofr.sbt._

seq(CompileThriftScrooge.newSettings: _*)

With the project files above, sbt should be able to use the tasks and settings of the sbt-scrooge plugin.

$ sbt
[info] Loading global plugins from /Users/jacek/.sbt/plugins
[info] Loading project definition from /Users/jacek/sandbox/tmp/sample-project/project/project
[info] Loading project definition from /Users/jacek/.sbt/staging/52a2b7ff1377492a32ff/project
[info] Loading project definition from /Users/jacek/sandbox/tmp/sample-project/project
[info] Set current project to default-fe8e50 (in build file:/Users/jacek/sandbox/tmp/sample-project/)
> about
[info] This is sbt 0.12.2
[info] The current project is {file:/Users/jacek/sandbox/tmp/sample-project/}default-fe8e50
[info] The current project is built against Scala 2.9.2
[info] Available Plugins: org.sbtidea.SbtIdeaPlugin, com.timushev.sbt.updates.UpdatesPlugin, net.koofr.sbt.CompileThriftScrooge
[info] sbt, sbt plugins, and build definitions are using Scala 2.9.2
> scrooge-version
[info] 3.0.43

For the other tasks and settings, write scrooge- and hit TAB.

> scrooge-[TAB]
scrooge-build-options                   scrooge-cache-folder                    scrooge-fetch                           scrooge-gen
scrooge-jar                             scrooge-name                            scrooge-thrift-external-source-folder   scrooge-thrift-include-folders
scrooge-thrift-namespace-map            scrooge-thrift-output-folder            scrooge-thrift-source-folder            scrooge-thrift-sources
scrooge-unpack-deps                     scrooge-version
like image 44
Jacek Laskowski Avatar answered Sep 26 '22 19:09

Jacek Laskowski