I’ve recently been asked a couple of times how to configure the request parameters for Maven’s outgoing HTTP requests.
The configuration are all added in the server element in settings.xml, in exactly the same way that you would add a password for a deployment repository, for example:
<servers> <server> <id>central</id> <configuration> <!-- configuration goes here --> </configuration> </server> </servers>
Note that the id must match that of the repository being used, with the default built in to Maven being central. However, if you use a repository manager (and you should!), the id must be that of the mirror, not the original repository. For example:
<servers> <server> <id>archiva.localhost</id> <configuration /> </server> </servers> <mirrors> <mirror> <id>archiva.localhost</id> <url>http://localhost:7777/archiva/repository/releases</url> <mirrorOf>external:*</mirrorOf> </mirror> </mirrors>
So what configuration is available?
useCache (Maven 2.0+) – if false, set the Pragma: no-cache header (for HTTP proxies). Default: false
<server> <id>archiva.localhost</id> <configuration> <useCache>true</useCache> </configuration> </server>
timeout (Maven 2.1+) – the connection timeout in milliseconds. Default: 60000.
<server> <id>archiva.localhost</id> <configuration> <timeout>5000</timeout> <!-- 5 seconds --> </configuration> </server>
httpHeaders (Maven 2.1+) – additional or overridden HTTP request headers
<server> <id>archiva.localhost</id> <configuration> <httpHeaders> <property> <name>User-Agent</name> <value>Internal-Build-System/1.0</value> </property> </httpHeaders> </configuration> </server>
More configuration parameters can be found by examining the available setters for the Wagon implementation in use. For example:
It should also be noted that the above technique works for other protocols, using the configuration available for the respective Wagon implementation in use, and also applies to any deployment if the id matches (note that in this case, the mirrors section is not relevant, so it will need to be configured for each deployment repository identifier).
An entirely separate option, if you are using Maven 2.1.0+, is the number of allowed concurrent download threads to use. This is configured via the maven.artifact.threads system property, as described in the configuration documentation.