How to use sbt from behind proxy?

sbt
supyo picture supyo · Dec 10, 2012 · Viewed 99.4k times · Source

How do I configure sbt to use a proxy?

For example, my build definition needs to connect to GitHub, specifying connection parameters for http.proxy, http.proxyPort, user, and password.

How would I pass in these settings to sbt?

Is there an easy way to switch between proxy/no-proxy settings for when I work from home?

Answer

Faiz picture Faiz · Dec 10, 2012

sbt respects the usual environment variables for http proxy settings:

export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=yourserver -Dhttp.proxyPort=8080 -Dhttp.proxyUser=username -Dhttp.proxyPassword=password"

(That's of course, assuming Unix (Linux/OSX etc). On windows you could just set the same environment variable (%JAVA_OPTS%) as usual in the Windows way.)

Then run sbt as usual:

sbt

Switching between proxy/no-proxy should be a matter of setting up a little script that you can 'slurp' in whenever you need it.

Gotchas

  • Don't include "http://" in the yourserver value
  • Don't include the port in the yourserver value
  • You probably also want to include https.proxyHost and https.proxyPort since a lot of stuff works over https
  • If your proxy requires authentication, don't even bother trying unless it just uses Basic Authentication as SBT doesn't support anything else. Also always beware clear texting credentials into environment variables! Be sure to remove the commands from your .bash_history using a text editing method that won't create trace files (technically you should shred or srm the entire file). If you are on Windows, don't worry about it, your security is already messed up you can't do any more harm.