Setting up a local p2 mirror for Tycho

Now that EclipseCon Europe is nearing, I decided to do some preparations. As most years some time will be spent on hacking, and this year is no exception especially with regards to the Science Working Group coding session at the Unconference.

These days many Eclipse based projects use Maven and Tycho for building. All my hobby projects are also using this technology. It’s quite nice, but a common problem is having to download artifacts when the network is bad or unavailable. From experience this happens a lot at EclipseCon Europe so I’m planning to avoid it. You can resolve this altogether by setting up a local artifact manager such as Nexus. Nexus supports both Maven and p2 repositories so if you have one of those you won’t need these instructions. I’ve set up Archiva on my NAS and rely on the local cache when the network is unavailable. However this only supports Maven artifacts and when building Eclipse based applications one also need the various dependencies. I’ve resolved this by creating local mirrors of the p2 repositories I often use, and instructed Maven to utilize these.

First you need a running HTTP daemon such as Apache on your system. I’m on OS X so I’m all set – just had to enable user directories after updating to Yosemite. Next you have to create the mirrors. This is done by calling the Eclipse mirror application. Once for the metadata and again for the artifacts. Replace path to eclipse and destination as appropriate.

If you’re on OS X and has upgraded to Eclipse 4.5 the patch to the eclipse executable is different:

Be prepared to wait quite a while for the last one to finish. If you want to speed it up you should try to find a faster mirror of the p2 repository. I repeated the process for SWTBot. Next I altered ~/.m2/settings.xml so it looks like this:

Once again, adjust the URL to suit your needs. Next it’s just a matter of making sure that the repositories referenced in the *.pom files match the mirrors. Just make sure that the identifiers are the same as the mirrorOf attribute in the configuration file or the mirrors will not be used.

That’s it. Happy coding!