Configuring Maven HTTP Connections

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

Example:

<server>
  <id>archiva.localhost</id>
  <configuration>
    <useCache>true</useCache>
  </configuration>
</server>

timeout (Maven 2.1+) – the connection timeout in milliseconds. Default: 60000.

Example:

<server>
  <id>archiva.localhost</id>
  <configuration>
    <timeout>5000</timeout> <!-- 5 seconds -->
  </configuration>
</server>

httpHeaders (Maven 2.1+) – additional or overridden HTTP request headers

Example:

<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.

About these ads

7 responses to “Configuring Maven HTTP Connections

  1. Hi brett Nice article.
    I have patched archiva 1.1.4 to use it with my sso engine (this patch is a http filter)
    My patch work fine with 2.0.9 maven client
    But unfortunately it seems to be blacklisted by my 2.1.0 maven client.
    So after some debugs I notice that my patch unauthorized request with no credential in request header.
    And mvn 2.10 does it why ???
    (my settings.xml and my pom are correct)

    Is it a special configuration http connection to correct this?

  2. Hi there,

    I have been trying to configure a mirror for the external maven repositories as central and others but for some reason the maven does not care about the server configuration:

    internal
    user
    pass

    and a mirror configured:

    internal

    http://archiva/repository/internal

    *

    I have the following archiva log :

    Authorization Denied [ip=192.168.10.108,permission=archiva-read-repository,repo=internal] : no matching permissions

  3. Hi Brett I need to work with this version of maven
    what is exactly the StreamWagon?
    Why it connect to the url?

    Thanks a lot for your answer…
    Do I need to ask another mailing list

  4. I am trying to use httpclient for wagon provider for there is a big file to upload from maven site process (I had outOfMemory Error). However, if I configure server in settings.xml like
    myid

    httpclient

    I have I am trying to use httpclient for wagon provider for there is a big file to upload from maven site process (I had outOfMemory Error). However, if I configure server in settings.xml like
    myid

    httpclient

    I have I am trying to use httpclient for wagon provider for there is a big file to upload from maven site process (I had outOfMemory Error). However, if I configure server in settings.xml like
    myid

    httpclient

    I have ” Cannot find setter nor field in org.apache.maven.wagon.providers.http.LightweightHttpWagon for ‘wagonProvider’ ” error. Is myconfiguration correct? I am using maven 2.2.1. Thank you in advance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s