Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can sbt pull dependency artifacts from git?

I've heard (and I know I've seen examples too, if only I can remember where) that sbt can obtain dependencies from a git repo.

I am looking to obtain the dependency harrah/up from github. The repository does not provide any artifact JAR files, only a source tree which is set up to be built using sbt. The process that I am imagining is that sbt will download the source repo, build it, and then use that as the dependency artifact.

I may be imagining that sbt can in fact do something like this. Can it? And if so, how?

like image 713
Owen Avatar asked Sep 26 '11 03:09

Owen


People also ask

How do I get dependencies from GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Insights. In the left sidebar, click Dependency graph. Optionally, under "Dependency graph", click Dependents.

Where are dependencies downloaded in SBT?

All new SBT versions (after 0.7. x ) by default put the downloaded JARS into the . ivy2 directory in your home directory. If you are using Linux, this is usually /home/<username>/.

How do we specify library dependencies in SBT?

The libraryDependencies key Most of the time, you can simply list your dependencies in the setting libraryDependencies . It's also possible to write a Maven POM file or Ivy configuration file to externally configure your dependencies, and have sbt use those external configuration files.

Which is the correct way to add dependencies in SBT file?

If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.


1 Answers

You can import unpackaged dependencies into your project from GitHub by treating them as project dependencies, using the dependsOn operator. (This is distinct from the way that precompiled library dependencies are included).

Note that you can specify which branch to pull using # notation. Here's some Scala SBT code that is working well for me:

object V {   val depProject = "master"   // Other library versions }  object Projects {   lazy val depProject = RootProject(uri("git://github.com/me/dep-project.git#%s".format(V.depProject))) }  // Library dependencies lazy val myProject = Project("my-project", file(".")) .settings(myProjectSettings: _*) .dependsOn(Projects.depProject) .settings(   libraryDependencies ++= Seq(... 

Note that if you have multiple SBT projects dependending on the same external project, it's worth setting up a central sbt.boot.directory to avoid unnecessary recompilations (see instructions here).

like image 177
Alex Dean Avatar answered Oct 03 '22 14:10

Alex Dean