Apache httpd config to cache the main maven repo
Posted Thu, 10 Jun 2010
The maven mirror documentation says pretty explicitly "Do not rsync the entire repo" - it recommends the use of caching proxies. We can do this trivially with apache httpd.
# httpd.conf: ProxyPass /maven/proxy http://repo1.maven.org/maven2 # What http path to cache for CacheEnable disk /maven/proxy # Where on disk to store the cached data CacheRoot /srv/repo/maven/proxy CacheDirLength 2 CacheDirLevels 3 # Override default cache expiration and control CacheDefaultExpire 2419200 CacheMaxExpire 2419200 # Ignore requests to not serve from cache. Maven data never changes. CacheIgnoreCacheControl On # Default max file size is 64K. Set to 1GB. CacheMaxFileSize 1073741824The above config will take requests to http://yourserver/maven/main/... and proxy them through to the main maven repo and also cache the fetch local to your webserver so future fetches will be local.
You tell maven to use your local repo in ~/m2/settings.xml:
<settings> <mirrors> <mirror> <id>local-mirror</id> <name>Local maven mirror</name> <-- Replace 'repo.local' with whatever your webserver's name is --> <url>http://repo.local/maven/proxy</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> </settings>Now all my maven dependency fetches are going through a local repo and files get cached to disk for future requests.
Since I already had a repo server for local rpm and rubygems, pushing this 5 line httpd config change with puppet was practically a no-op in terms of implementation.