How to make SBT use local maven repository?

58 views Asked by At

I have the following configuration in sbt build.sbt under the root project:

resolvers += {

  val path = "file://" + Path.userHome.absolutePath + "/.m2/repository"

  println(s" === MVN PATH ===")
  println(path)
  "Local Maven Repository" at path
}

externalResolvers += {

  val path = "file://" + Path.userHome.absolutePath + "/.m2/repository"

  println(s" === MVN PATH ===")
  println(path)
  "Local Maven Repository" at path
}

When running it (sbt compile), I encounter the following error:

 === MVN PATH ===
file:///home/peng/.m2/repository
[info] Updating 
[info] Resolved  dependencies
[warn] 
[warn]  Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading io.tryp:splain_2.13.12:1.1.0-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /home/peng/.ivy2/local/io.tryp/splain_2.13.12/1.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/io/tryp/splain_2.13.12/1.1.0-SNAPSHOT/splain_2.13.12-1.1.0-SNAPSHOT.pom
[error]     at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:344)

Whys is it not working, is SBT buggy on this?

1

There are 1 answers

0
Gaël J On

It's not in the build.sbt but if you're gonna need this for all projects, this can be done in the ~/.sbt/repositories config file with:

[repositories]
local
maven-local

This will add the two local repositories: the one from Coursier and the one from Maven.