Infrastructure worth keeping — and kept patched.

Maven build cache extension behind a corporate proxy

Maven has its own proxy settings, and the Apache Build Cache Extension follows them. This page shows what the extension sent through a proxy, how it differs from Gradle, and what you see when the proxy says no. All of it was run for real with Maven 3.10.0, extension 1.2.3 and FosterStack Cache 0.2.1.

What was tested, and what was not

The settings

In ~/.m2/settings.xml, next to the cache's password entry:

<settings>
  <servers>
    <server>
      <id>fosterstack-cache</id>
      <username>maven</username>
      <password>your-password-or-CI-secret</password>
    </server>
  </servers>
  <proxies>
    <proxy>
      <id>corp</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>3128</port>
      <nonProxyHosts>cache.internal.example.com|localhost</nonProxyHosts>
    </proxy>
  </proxies>
</settings>

The cache itself is set up as in the Maven setup. The server id must still match the remote's.

What went through the proxy

With the proxy configured, all of the extension's cache traffic went through it: the lookups, the download that restores a build, and the uploads. This is what the proxy logged for two builds, the first filling the cache and the second restoring from it (the proxy also saw Maven's own traffic to repository.apache.org, which is not shown):

build 1 (stores)
GET http://<cache-ip>:18132/v1.1/demo/demo/<id>/buildinfo.xml
GET http://<cache-ip>:18132/v1.1/demo/demo/<id>/buildinfo.xml
PUT http://<cache-ip>:18132/v1.1/demo/demo/<id>/demo.jar
PUT http://<cache-ip>:18132/v1.1/demo/demo/<id>/buildinfo.xml
PUT http://<cache-ip>:18132/v1.1/demo/demo/<id>/build-cache-report.xml

build 2 (restores)
GET http://<cache-ip>:18132/v1.1/demo/demo/<id>/buildinfo.xml
GET http://<cache-ip>:18132/v1.1/demo/demo/<id>/buildinfo.xml
GET http://<cache-ip>:18132/v1.1/demo/demo/<id>/demo.jar
PUT http://<cache-ip>:18132/v1.1/demo/demo/<id>/build-cache-report.xml

The second build logged Found cached build, restoring demo:demo from cache.

Other cases

SetupWhat happened
Proxy configured, cache URL is 127.0.0.1Still went through the proxy (4 requests logged). Unlike Gradle, Maven does not skip the proxy for loopback.
Proxy configured, the cache's address in <nonProxyHosts>Nothing reached the proxy. The build still restored from the cache.
Proxy refuses the cache's hostNothing was stored or restored. The build succeeded without the cache, and logged Error downloading cache item with HTTP Status: 403.
Proxy not running at allThe lookup failed with Connect to 127.0.0.1:18131 ... Connection refused. The build succeeded without the cache, and nothing was uploaded.

Things that catch people

Related: Maven build cache extension not restoring and a production setup with TLS.

Maven remote cache setup FosterStack home