Monday, January 7, 2013

Tycho build 2: Global maven settings

In this tutorial we will look at some global maven settings to adjust how to access remote resources.

Tycho Tutorials

For a list of all tycho related tutorials see Tycho Tutorials Overview

Maven Settings

When maven is executed, it reads a global settings file which you should adapt to your needs. You can find its location in Preferences/Maven/User Settings. If you update the file you should either restart eclipse or click Update Settings on the preferences page.


Setting a network proxy

Maven needs network access. At least during the first runs it typically needs to download some catalogs. If you are located behind a proxy you might expect that maven honors your eclipse proxy settings. But as maven is an external tool, it does not honor your eclipse proxy settings. You have to enter them manually in the configuration file:

<settings>
 .
 .
 <proxies>
  <proxy>
   <active>true</active>
   <protocol>http</protocol>
   <host>proxy.somewhere.com</host>
   <port>8080</port>
   <username>proxyuser</username>
   <password>somepassword</password>
   <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
  </proxy>
 </proxies>
 .
 .
</settings>

As more and more sites change to https you might also need to add a separate proxy setting for https. For me it did not work out to provide something like http|https in the protocol section. Instead I added a second proxy node for the https protocol.

I faced some problem accessing an NTLM proxy when using the embedded maven engine (you may set this in your run target). For me it worked to install an external maven version and use that for builds that need to access the internet over a proxy.

Read the documentation for more details.

Setting repository mirrors

In the first tutorial we used the Juno download site to resolve our build dependencies. Maven allows to define mirrors for repositories which we can put in the global settings file:
<settings>
 .
 .
 <mirrors>
  <mirror>
   <id>Mars_local</id>
   <mirrorOf>Mars</mirrorOf>
   <name>Local mirror of Mars repository</name>
   <url>file://C/some_folder/</url>
   <layout>p2</layout>
   <mirrorOfLayouts>p2</mirrorOfLayouts>
  </mirror>
 </mirrors>
 .
 .
</settings> 

The important parameter is mirrorOf. It contains the id of the original repository as defined in our pom file. As a consequence maven will favor our local mirror to resolve dependencies.Take care that your local repository is up to date as maven will not connect to the original repository anmore to resolve dependencies.

When you share your poms with your team everybody will be able to build the project. Still you can use local mirrors for faster (or network independent) builds.

4 comments:

  1. Hi,

    I've set up repository mirror in /.m2/settings.xml as follows:



    local-mars
    repo-mars
    Local Mirror of Mars Repository
    file:/home/micha/.m2/mirrors/mars
    p2
    p2



    It had been worked fine for quite some time until suddenly during build Maven complains for not being able to find the repository:

    org.eclipse.equinox.p2.core.ProvisionException: No repository found at file:/home/micha/.m2/mirrors/mars

    Strangely this only happens during eclipse-feature build.

    Any help would be greatly appreciated.

    Thanks & Regards
    Micha

    ReplyDelete
    Replies
    1. posting xml does not work, so I can only guess what you did: setting up a local proxy within the .m2 cache folder? not a good idea. use the tycho p2-mirror job to fetch a local mirror, but do not place it into the cache directory of maven.

      Delete
    2. Hi Christian,

      So far I use Eclipse to create the mirror.

      Regarding tycho p2-mirror job, are you referring to tycho-p2-extras-plugin ?

      If so, since this is not something we execute often, in which pom should I include it ?

      Regards,
      Micha

      Delete
    3. you could use that job or look at my tutorial on how to mirror repositories

      Delete