Why does Maven disable HTTP request caching?

The default Maven settings for HTTP requests, such as those used by Maven to extract artifacts from repositories, include the following headers:

Cache-control: no-cache Cache-store: no-store Pragma: no-cache Expires: 0 Accept-Encoding: gzip 

This is similar to documentary behavior . By default, Maven Universal for HTTP (i.e., the Lightweight Client) does not seem to allow these headers to be disabled.

Why is Maven configured this way by default? For artifacts that actually have versions, they should never change, right?

I work in an environment where many developers share a common HTTP proxy, and this behavior means that developers never benefit from caching. And we have dependencyManagement in all our dependencies and do not use SNAPSHOT or other versions that may change, so it seems that caching should be safe.

What can I put in my settings.xml or pom.xml to disable these headers and allow our proxy to cache responses and return them?

+6
maven-2 wagon
source share
1 answer

This is apparently documented behavior. By default, Maven Universal for HTTP (i.e., the Lightweight Client) does not seem to allow these headers to be disabled.

In fact, you can configure the Lightweight HTTP Wagon client using available setters, for example (Maven 2.0+):

 <servers> <server> <id>central</id> <configuration> <useCache>true</useCache> </configuration> </server> </servers> 

Or even override or provide additional HTTP headers (Maven 2.1 +):

 <server> <id>central</id> <configuration> <httpHeaders> <property> <name>User-Agent</name> <value>Internal-Build-System/1.0</value> </property> </httpHeaders> </configuration> </server> 

This is well covered by Brett Porter's Configure Maven HTTP Connections .

Why is Maven configured this way by default?

Wild hunch: this is safe by default to avoid problems with poorly configured proxies (not quite sure if this is true).

What can I put in my settings.xml or pom.xml to disable these headers and allow our proxy to cache responses and return them?

The above settings go to settings.xml (of course, if necessary, adjust id , central for the default repository used by Maven).

If it doesn’t work (should), an alternative would be to go back to the HTTPClient Wagon and configure it as described in Advanced configuration of the HTTP carriage HttpClient .

References

+7
source

All Articles