This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.11, “Telling SBT How to Find a Repository (Working with Resolvers).”
Problem
In a Scala SBT project, you want to add a managed dependency to your project from an Ivy repository that SBT doesn’t know about by default.
Solution
Use the resolvers
key in the build.sbt file to add any unknown Ivy repositories. Use this syntax to add one resolver:
resolvers += "Java.net Maven2 Repository" at "http://download.java.net/maven/2/"
You can use a Seq
to add multiple resolvers:
resolvers ++= Seq(
"Typesafe" at "http://repo.typesafe.com/typesafe/releases/",
"Java.net Maven2 Repository" at "http://download.java.net/maven/2/"
)
Or, if you prefer, you can also add them one line at a time, making sure to separate them by a blank line:
resolvers += "Typesafe" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Java.net Maven2 Repository" at "http://download.java.net/maven/2/"
Discussion
If the module you’re requesting is in the default Maven2 repository SBT knows about (at http://search.maven.org/#browse), adding a managed dependency “just works.” But if the module isn’t there, the library’s author will need to provide you with the repository information.
You define a new repository in SBT’s build.sbt file with this general format:
resolvers += "repository name" at "location"
As shown in the Solution, you can enter one resolver at a time with the +=
method, and you can add multiple resolvers with ++=
and a Seq
.
In addition to the default Maven2 repository, SBT is also configured to know about the “JavaNet1Repository” at http://download.java.net/maven/1/. To use this repository in your SBT project, add this line to your build.sbt file:
resolvers += JavaNet1Repository
this post is sponsored by my books: | |||
#1 New Release |
FP Best Seller |
Learn Scala 3 |
Learn FP Fast |