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
.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With