82

I'm having problems with a maven dependency which is in my local respository.

SBT can't find it. Already set log level to debug, but not getting anything new.

The files are in the repository. I copy paste paths from the console to file explorer and they are there.

The output:

[debug]          trying file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.pom

[debug]                 tried file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.pom

[debug]         Local Maven Repository: resource not reachable for com/twitter#naggati;2.0.0: res=file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0
.0/naggati-2.0.0.pom

[debug]          trying file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.jar

[debug]                 tried file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0.0/naggati-2.0.0.jar

[debug]         Local Maven Repository: resource not reachable for com/twitter#naggati;2.0.0: res=file://c:/Users/userz/.m2/repository/com/twitter/naggati/2.0
.0/naggati-2.0.0.jar

[debug]         Local Maven Repository: no ivy file nor artifact found for com.twitter#naggati;2.0.0

Edit: I added the path using scala file in project/build like described in http://code.google.com/p/simple-build-tool/wiki/LibraryManagement

"sbt can search your local Maven repository if you add it as a repository:"

val mavenLocal = "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository"

That made sbt look in the local repository. Before it didn't.

So the scala file looks like this:

import sbt._

class Foo(info: ProjectInfo) extends DefaultProject(info) {

val mavenLocal = "Local Maven Repository" at "file://c:/Users/userz/.m2/repository"

}

(I hardcoded Path.userHome to exclude possible error reason. As expected it didn't change anything).

5
  • 1
    You have to add the local maven repo to your build.sbt
    – leedm777
    May 27, 2012 at 16:12
  • The repository is added, otherwise the script would not look there for the files.
    – User
    May 27, 2012 at 17:48
  • How is the line that tells sbt to look for your dependency? If you have something like ... -> default, remove default from there.
    – fmpwizard
    May 27, 2012 at 19:01
  • Actually I'm not using build.sbt. I'm using a scala file like described in code.google.com/p/simple-build-tool/wiki/LibraryManagement. Edited my post with more details.
    – User
    May 27, 2012 at 19:16
  • 1
    ixx: That's SBT 0.7.x, and it's the legacy version. You should update to [SBT 0.11.x])github.com/harrah/xsbt/wiki), if possible.
    – leedm777
    May 28, 2012 at 1:40

4 Answers 4

161

Just add this line in the build.scala or build.sbt file

resolvers += Resolver.mavenLocal
5
  • 2
    Which sbt is that? I used it with 0.13.11 and it works just fine.
    – marios
    Oct 14, 2016 at 20:23
  • 6
    resolvers in Global := Resolver.mavenLocal works for me.
    – retronym
    Oct 29, 2017 at 23:39
  • OMG I've searched an hour for this perfect solution! Thx Nov 10, 2018 at 1:20
  • @retronym, I think you meant "resolvers in Global += Resolver.mavenLocal"
    – Ben McCann
    Mar 3, 2019 at 3:07
  • 3
    For SBT 1.3.x it's ThisBuild / resolvers += Resolver.mavenLocal
    – antex
    Nov 26, 2019 at 16:12
65

You need three slashes after the file: specifier. This is because between the second and third slash, you have an optional hostname. Wikipedia has a good explanation of file: URL's

You're having a problem because the typical pattern of "file://"+Path.userHome+"/.m2/repository" assumes a Unix filesystem, where the path begins with a /, contains no :, and usually contains no spaces.

To have a non-hardcoded path that works on both Windows and Linux/Unix, use:

"Local Maven" at Path.userHome.asFile.toURI.toURL + ".m2/repository"
1
  • not with projects defined and adding to the project doesn't work either
    – pferrel
    Aug 5, 2017 at 22:38
21

To get this to work for newer versions of sbt, add the following to build.sbt:

resolvers += "Local Maven Repository" at "file:///"+Path.userHome+"/.m2/repository"
2
  • 1
    No matter what I do I still get this error when doing sbt compile: [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: UNRESOLVED DEPENDENCIES :: [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: com.sanoma.cda#maxmind-geoip2-scala_2.11;1.3.2: not found [warn] :::::::::::::::::::::::::::::::::::::::::::::: [trace] Stack trace suppressed: run last :update for the full output. [error] (:update) sbt.ResolveException: unresolved dependency: com.sanoma.cda#maxmind-geoip2-scala_2.11;1.3.2: not found
    – bashan
    Feb 6, 2015 at 21:35
  • I used resolvers in Global += "Local Maven Repository" at "file://" + Path.userHome + "/.m2/repository" May 30, 2020 at 23:35
3

Watch out when you have a project defined, you'll need to include the resolver in the settings. Global resolver will not be identified.

Example:

lazy val core = (project in file("core")).
  settings(commonSettings: _*).
  settings(
    resolvers += Resolver.mavenLocal,
    name := "Core",
    libraryDependencies := coreDependencies
  )
2
  • doesn't work for me, though it may have something to do with projects
    – pferrel
    Aug 5, 2017 at 22:36
  • 1
    Thanks Dyin, It worked. Added resolver to commonSettings, now all defined projects can look into local maven repo for dependencies.
    – raevilman
    Oct 6, 2017 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.