18.11. Telling SBT How to Find a Repository (Working with Resolvers)

Problem

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, 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 the 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 configured to know about the JavaNet1Repository. To use this repository in your SBT project, add this ...

Get Scala Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.