How to set leiningen2's proxy.

There’s an old post out there that documents how to configure leiningen to use a proxy. It’s fantastic and points to all the right information, but for the old version of leiningen.

With leiningen2 in the slow process of being released, it strikes me as an appropriate time to update that documentation, as it’s now entirely incorrect as leiningen no longer use Maven, but Aether, to resolve dependencies.

Simple Route: Set your environments http_proxy and https_proxy correctly.

Leiningen now knows how to honor those variables. When it attempts to grab dependencies and push things to Clojars, etc, it will default to the values found there. Note that those variables are both the host and the port, i.e. 123.456.789.101:89.

Custom Route: Set the :jvm-opts section in your user profile.

If you need leiningen to have a custom proxy that won’t work for other components in your system, then you can’t set the whole she-bang with an environment variable.

Enter profiles.

Profiles are the preferred way to change the configuration of many projects or provide plugins that are useful mainly to you and not to everyone that might work on the project (like lein-swank, for instance).

There are a few profiles active at all times unless configured not to be active: :dev, :user, and :default. That means that you can configure any of those in the ~/.lein/profiles.clj and it will take effect for all runs.

To configure the :user profile, open up or create the ~/.lein/profiles.clj and enter something like the following:

{:user {:jvm-opts ["-Dhttp.proxyHost=" "-Dhttp.proxyPort=8080"]}}

Note a couple of things:

  1. In good Clojure tradition, configuration is done via a plain map.
  2. Specifying which profile your configuring is done by specifying that profile as a keyword. To define more, you just add another entry to the map. A profile can be any valid keyword.
  3. :jvm-opts is a key that leiningen knows about which is a vector of strings that will be passed to the JVM that leiningen starts. Think clojure.java.shell/sh call where multiple arguments are specified as multiple strings.

Short but sweet! Hope it helps.