Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sbt

I forked a Scala library from GitHub, and I want to import it to another project.

How can I tell sbt where to find this package?

For example, I'm writing a program in ~/code/scala/myProgram, and I want to import a library from ~/code/scala/otherlib.

like image 953
Emil Avatar asked Mar 16 '14 03:03

Emil


People also ask

How do I clone from GitHub to IntelliJ?

You can clone a repository that you want to contribute to directly from IntelliJ IDEA and create a new project based on it. From the main menu, choose Git | Clone. If the Git menu is not available, choose VCS | Get from Version Control. In the Get from Version Control dialog, choose GitHub on the left.


2 Answers

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.

like image 133
Mike Allen Avatar answered Nov 07 '22 06:11

Mike Allen


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.

like image 39
Jacek Laskowski Avatar answered Nov 07 '22 07:11

Jacek Laskowski