Table of Contents

  1. Use Proxy Repositories
  2. Use Self Hosted Repositories
  3. Use Both

Config sbt to Use Both Proxy and Self Hosted Repositories

Posted on 11 Jul 2016, tagged sbtscala

While building Scala projects, we usually use a proxy to make the build faster. On the other hand, we usually use another repository to host our internal dependencies, which usually has a password to protect it from unwanted access. Both things are good and necessary. But if you want to use both of them, you will find it’s very tricky.

Use Proxy Repositories

sbt has a document that described how to set proxy repositories:

Config repositories in ~/.sbt/repositories like this:

2  local
3    my-ivy-proxy-releases:, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
4    my-maven-proxy-releases:

Add while use sbt command.

The second step will override all the resolvers defined in your project, like in the file build.sbt. It is necessary because if you don’t do this, sbt will still send requests to default repos like typesafe and scala-sbt.

Use Self Hosted Repositories

sbt has a document about this, too. You will add something like this in your build.sbt:

1resolvers +=
2  "Sonatype OSS Snapshots" at ""

And if you have a password for this repo, you should also add something like this:

1credentials += Credentials("Sonatype Nexus Repository Manager", "",
2  "username", "password")

Use Both

You may see the problem to use both of them. In order to force sbt to use proxy repos, you should use the option, which will override your self hosted repo written in build.sbt.

After tried some methods, I find I can just write the repos defined in build.sbt into ~/.sbt/repositories, and sbt will still be able to find the credentials for it while building the project.

This method will make sbt print some error logs while loading the project: sbt will attempt to download some dependencies from this repo but cannot find the credential since it hasn’t loaded the project yet. If you are comfortable to ignore the error log, this method would be fine.

comments powered by Disqus