Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can SBT refresh git uri dependency (always or on demand)?

Tags:

git

sbt

I have the following sbt code to add a plugin dependency on a git uri:

import sbt._

object Plugins extends Build {
  lazy val username = ("git config --global user.bitbucket" !!).trim

  lazy val root = Project("root", file(".")) dependsOn(
    uri(s"https://[email protected]/team/build.git#build_0.1")
  )
}

This works fine, but I find that if I make changes to build_0.1 and push it, when I come to compile the project again, sbt does not pull the changes I've made so I have an out of date plugin.

How can I get SBT to always do a git pull on the dependencies it depends on?

like image 560
user3180279 Avatar asked Jan 16 '14 22:01

user3180279


1 Answers

SBT up to 0.13.2-M1 supports git clone and git checkout only.

git clone is used when the URL doesn't contain # to point at a branch or a commit, e.g.

git:file:///Users/jacek/sandbox/so/sbt-git/git-repo

git checkout is executed when the URL has # in the URL that points at a branch or a commit, e.g.

git:file:///Users/jacek/sandbox/so/sbt-git/git-repo/#a221379c7f82e5cc089cbf9347d473ef58255bb2

When I commit'ed a change to a git repo, I had to update the commit hash in build.sbt, too, to have the change referenced in the SBT project (the val v below).

lazy val v = "a221379c7f82e5cc089cbf9347d473ef58255bb2"

lazy val g = RootProject(uri(s"git:file:///Users/jacek/sandbox/so/sbt-git/git-repo/#$v"))

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

With changes in the git repository, the SBT project has to be reload'ed so a new checkout can be run and the project gets refreshed.

[root]> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/sbt-git/project
Cloning into '/Users/jacek/.sbt/0.13/staging/24535507588417c1c2dc/git-repo'...
Checking connectivity... done
[info] Set current project to root (in build file:/Users/jacek/sandbox/so/sbt-git/)
[root]>

It's painful, but does the trick (and let you track where you are with the remote git repo).

You may also find Can multi-projects from GIT be used as SBT dependencies? useful.

like image 81
Jacek Laskowski Avatar answered Sep 28 '22 15:09

Jacek Laskowski