Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use sbt from behind proxy?

Tags:

sbt

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?

like image 434
supyo Avatar asked Dec 10 '12 15:12

supyo


1 Answers

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.
like image 85
Faiz Avatar answered Sep 30 '22 17:09

Faiz