user266003
user266003

Reputation:

Using Git local repository as dependency in SBT project?

I cloned a repository from GitHub to my local machine, changed it to fit my needs and now I'm going to use it in my project. I guess I must use .jar file from it. However, there is no such a file.

Do I have to generate it myself?

Also, how do I refer to it? I don't want to copy it to /lib folder for now because I keep working on the cloned project. As I found out I have to use this:

resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository" 

However, I don't have the file build.sbt, I only have file a plain scala file titled Build.scala and it's not possible to use code above in it.

Also, it says /.m2/repository, but how does it know where .jar file is in this repository?

Upvotes: 1

Views: 2560

Answers (1)

Jacek Laskowski
Jacek Laskowski

Reputation: 74709

Since the project comes from GitHub I assume it's a git project. The solution is to use RootProject with git URI as a reference to your cloned git project.

Say you cloned the project to /Users/jacek/sandbox/so/sbt-git/git-repo (as I did in Can SBT refresh git uri dependency (always or on demand)?).

Do git log to find out the last commit you want to reference and use it in the git URI of the referenced project in SBT - in dependsOn.

Given the last commit is a221379c7f82e5cc089cbf9347d473ef58255bb2, build.sbt could look as follows:

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

It's also possible to leave out the commit id and keep up with the development in the referenced git project after it's updated with git fetch followed by git merge as described in git-pull(1) Manual Page.

Upvotes: 4

Related Questions