Clj to use a non-default maven repository

Hi,

I’m behind a corporate wall and cannot run clj as I cannot access the default maven repository.

Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact org.clojure:clojure:pom:1.12.0 from/to central (Central Repository:): Connect to repo1.maven.org:443 [repo1.maven.org/151.101.188.209] failed: connect timed out

But the alternative https://repo.maven.apache.org/ is accessible.

As I’m using lein, tried to change the configuration like this:

$ cat ~/.lein/profiles.clj
{:mirrors {“central” {:url “Central Repository:”}}}

But it didn’t solve the issue and still cannot run clj.

What should I do to replace the blocked repo by the whitelisted one?

clj is completely independent of Leiningen, so configuring the latter will not affect the former.

Try editing the ~/.clojure/deps.edn file and adding :mvn/repos there, as described here: Clojure - deps.edn Reference

1 Like

I changed that but still cannot connect to the repo.

Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact org.clojure:clojure:pom:1.12.0 from/to central (https://repo.maven.apac
he.org/maven2/): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.72.215] failed: connect timed out

clj has to use a http_proxy to access the repo.
At https://clojure.org/reference/deps_edn there seems to be no reference to proxies.
How to tell clj to use one?

clj has to use a http_proxy to access the repo.

clj doesn’t have to use the http_proxy environment variable, it just has to use the right HTTP proxy. The environment variable is specific to Leiningen and might differ for other software.

How to tell clj to use one?

I don’t know, I usually configure a system-wide proxy in a way that routes all the requests to particular hosts to that proxy.

With the proxy settings configured, I can access https://repo.maven.apache.org/maven2/ from a text web browser, like links.

But clj cannot do it, from the same terminal session.

I’m not sure what a terminal session would have to do with anything here. But how did you configure the proxy settings so that links works?

In bash, I’ve setup:

https_proxy=proxy.gateway:8080
http_proxy=proxy.gateway:8080

env | grep proxy

Shows these are setup.

Well, as I said - those environment variables are not something standard that must be respected by everything that uses network. Some programs might use those vars, some might not, some might even expect a different format in them.

E.g. on my machine, links doesn’t respect those variables at all, I have to provide the -http-proxy option via its CLI or configure a system-wide proxy.

Judging by the source code, clj should respect any Maven settings you put into ~/.m2/settings.xml, and that file allows you to configure proxies as well.

1 Like

It’s solved.

This URL https://maven.apache.org/settings.html#Servers shows some examples of building the ~/.m2/settings.xml file.

To whom it might be useful, the contents of that file (for my case) are:

  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>apache</id>
      <name>Maven Apache</name>
      <url>https://repo.maven.apache.org/maven2/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  <proxies>
    <proxy>
      <id>proxy_e</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.gateway</host>
      <port>8080</port>
      <!--<username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts> -->
    </proxy>
  </proxies>
</settings>

Thank you very much @p-himik!
So that you receive in double the help you gave me!

been looking for something like this for a while (but using a socks proxy). With lein it was pretty trivial; nobody had an answer to clj. This looks like a path forward, thanks for running it down.