How do I use Archiva as a mirror of the maven central repository?
Author: Deron Eriksson
Description: This tutorial describes how to use Archiva as a mirror of the maven central repository.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


In another tutorial, we saw how to install and run the standalone distribution of ArchivaS. By default, Archiva comes with a proxy to the mavenSW central repository. Therefore, it's basically all set up to be used as a mirror of the maven central repository. If we make a request of Archiva for an artifact for a central repository artifact, it will download that artifact and return that artifact to us. If we make future requests for that artifact, Archiva will return to us the copy of the artifact that it had already downloaded from the central repository.

Let's try this out. To do this, in our settings.xml file we need a "mirror" entry that points to the URL for our Archiva repository. The mirrorOf element specifies "central", the super pomW id for the maven central repository. I'll call this mirror "archiva.central", since this is an archivaS mirror of the central repository.

archiva mirror of the maven central repository from settings.xml

		<mirror>
			<id>archiva.central</id>
			<url>http://192.168.1.7:8081/archiva/repository/internal</url>
			<mirrorOf>central</mirrorOf>
		</mirror>

Now, I'll add a new dependency to my "mytest" project. I'll add version 2.3 of the "commons-lang" dependency.

Adding the "commons-lang" dependency to pom.xml

		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>2.3</version>
			<scope>compile</scope>
		</dependency>

My updated pom.xml file (with the commons-lang dependency) is shown here:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.maventest</groupId>
	<artifactId>mytest</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>mytest</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>2.3</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>
</project>

Now, I'll run the maven "eclipse:eclipse" goal on the "mytest" project:

Executing 'mvn eclipse:eclipse' on 'mytest' project

The console output from "mvn eclipse:eclipse" on "mytest" is shown here:

Console output from 'mvn eclipse:eclipse'

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'eclipse'.
[INFO] ------------------------------------------------------------------------
[INFO] Building mytest
[INFO]    task-segment: [eclipse:eclipse]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing eclipse:eclipse
[INFO] No goals needed for project - skipping
[INFO] [eclipse:eclipse]
Downloading: http://192.168.1.7:8081/archiva/repository/internal/commons-lang/commons-lang/2.3/commons-lang-2.3.pom
4/10K
8/10K
10/10K
10K downloaded
Downloading: http://192.168.1.7:8081/archiva/repository/internal/commons-lang/commons-lang/2.3/commons-lang-2.3.jar
4/239K
... [cut for clarity]
239/239K
239K downloaded
[INFO] Using source status cache: C:\dev\workspace\mytest\target\mvn-eclipse-cache.properties
[INFO] Not writing settings - defaults suffice
[INFO] File C:\dev\workspace\mytest\.project already exists.
       Additional settings will be preserved, run mvn eclipse:clean if you want old settings to be removed.
[INFO] Wrote Eclipse project for "mytest" to C:\dev\workspace\mytest.
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Thu Feb 07 09:47:37 PST 2008
[INFO] Final Memory: 3M/7M
[INFO] ------------------------------------------------------------------------

Notice in the console output that the common-lang pom and jarW files were downloaded to our local maven repository from our Archiva mirror rather than from the central repository.

If we browse Archiva, we can see that commons-lang has been added to the Archiva repository.

commons-lang 2.3 added to Archiva repository

Easy, huh?