SBT doesn't find file in local maven repository although it's there

ScalaMavenSbt

Scala Problem Overview


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).

Scala Solutions


Solution 1 - Scala

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

resolvers += Resolver.mavenLocal

Solution 2 - Scala

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"

Solution 3 - Scala

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"

Solution 4 - Scala

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
  )

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUserView Question on Stackoverflow
Solution 1 - ScalaBen Rhouma ZiedView Answer on Stackoverflow
Solution 2 - Scalaleedm777View Answer on Stackoverflow
Solution 3 - ScalaMariusView Answer on Stackoverflow
Solution 4 - ScalaDyinView Answer on Stackoverflow