12

I'm setting up the dependencies for my first Scala project using SBT.

This is my build.sbt file:

name := "MyProj"

version := "1.0"

scalaVersion := "2.9.2"

libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "2.0.0.201206130900-r"

When I run update inside the interactive mode, it updates something from org.scala-lang... but it never downloads my dependencies. How do I get it to install/download dependencies?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Tower
  • 98,741
  • 129
  • 357
  • 507

1 Answers1

14

Some of the common repositories are already predefined, but it looks like your library is not in them, so you have to add the Eclipse repository to the list of resolvers (add this line to build.sbt):

resolvers += "jgit-repository" at "http://download.eclipse.org/jgit/maven"

just like you would in maven (with <repository>...</repository> record)

Don't forget to reload your sbt console and then update to fetch the dependency or just start sbt afresh.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
  • I added that code line, but it still does not even seem to detect my dependencies. It does not mention anything about them? – Tower Aug 31 '12 at 17:53
  • 1
    @rFactor are you sure, that you've restarted SBT in order to apply new settings? – om-nom-nom Aug 31 '12 at 17:54
  • 3
    Oh, I had to exit and rerun `sbt` :/. My bad. – Tower Aug 31 '12 at 17:57
  • Now it seems it downloads the dependencies, but I can't seem to find the files anywhere under my project. Do they go somewhere else? How can I use these dependencies? – Tower Aug 31 '12 at 18:29
  • 3
    usually, they goes to the `~/.ivy2/cache/` directory, so they can be reused by other projects (in section Managed Dependencies [of sbt wiki](https://github.com/harrah/xsbt/wiki/Getting-Started-Library-Dependencies) you may find a full info) – om-nom-nom Aug 31 '12 at 18:32
  • Okay that is cool, but how can I import it and use it now? I'm using IntelliJ IDEA and it has no idea that a dependency like that exists and compilation fails and I'm getting "cannot resolve symbol". – Tower Aug 31 '12 at 18:34
  • @rFactor to use them from IntelliJ IDEA use this plugin https://github.com/mpeltonen/sbt-idea and look at this question http://stackoverflow.com/questions/4250318/how-to-create-sbt-project-with-intellij-idea for details – om-nom-nom Aug 31 '12 at 18:35
  • Can't I install them locally inside my project? – Tower Aug 31 '12 at 18:42
  • Yes, [you can](http://stackoverflow.com/questions/3142856/configure-sbts-ivy-cache-directory-per-user-or-system-wide) – om-nom-nom Aug 31 '12 at 18:44
  • I think I don't want to add that burden to anyone contributing to my project so I guess it's best to manually handle dependencies, Git has submodules anyway. – Tower Aug 31 '12 at 18:47
  • 2
    @rFactor managed dependencies **are not meant to be done in that way**, they are just enlisted in build file, and every contributer simply issues `update` command and they automatically gets autoresolved -- that's how maven, ivy, lein, sbt and others build tools work. I highly don't recommend you to store dependencies as jar files directly inside your project – om-nom-nom Aug 31 '12 at 18:52