How can SBT project import library from GitHub cloned to local directory?

If it is supported by the project you have cloned (that is, if it supports SBT and is configured to publish to a repository), you can publish it locally with the sbt command sbt publish-local. For example:

cd ~/code/scala/otherlib
sbt publish-local

This will build and publish this library in your local Ivy repository (typically ~/.ivy2/local). Note that you will need to repeat this each time you modify the otherlib sources.

After the project's published locally to the local Ivy repository, you can specify otherlib as a dependency in your SBT project, using the regular SBT dependency for the original version of the forked library (assuming that you haven't changed its ID, version, group ID, etc.). For example, by adding:

libraryDependencies += "com.some_company" % "otherlib" % "1.0.0"

to your build.sbt file.

Now, when you build your project, it will find otherlib in your local Ivy repository (as if it'd been pulled down from a regular repository) and will use your custom version of it.

If otherlib doesn't support SBT, or isn't configured to publish to a repository, and you do not want to modify it to do so, then you can simply copy its .jar file(s) to the /lib directory (~/code/scala/myProgram/lib) of your project.


SBT supports git repositories out of the box. The support is for clone and checkout. See my answer to Can SBT refresh git uri dependency (always or on demand)? or Using Git local repository as dependency in SBT project?, that boil down to the following in build.sbt:

lazy val gitRepo = "git:file:///Users/jacek/sandbox/so/sbt-git/git-repo/#master"

lazy val g = RootProject(uri(gitRepo))

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

Once you define the dependency (between projects) you can use it - the git-hosted project - with no other configuration.

Tags:

Sbt