Tuesday, December 26, 2006

Apache Archiva - Part One

Sure, you love Maven. We all do. If used correctly it can simplify even your ginourmous build processes, or I'll eat my hat (metaphorically - I no longer wear a hat). But managing your own remote repositories is still a pain for any organization. Enter: Archiva. Let's take a look at this repository management tool from the folks who brought you Maven - as well as the dark underbelly of managing large public repositories.

Archiva is not yet available for download, but it is becomming fairly stable, so here is a sneaky-peeky. First, download it via Subversion:
svn co \
http://svn.apache.org/repos/asf/maven/archiva/trunk \
archiva
Now, an annoying part of javax not yet in any repositories, is that you must manually install a required artifact first. JavaX Connector version 1.0. It can be downloaded from http://java.sun.com/j2ee/connector/download.html, then installed via:
mvn install:install-file -DgroupId=javax.resource \
-DartifactId=connector \
-Dversion=1.0 \
-Dpackaging=jar \
-Dfile=connector.jar
Where "connector.jar" includes the path to the connector.jar you just downloaded. That should be the hardest part of the setup. Next, in the base archiva directory, run
mvn install
If any tests fail (it is trunk afterall), try and run with
mvn -Dmaven.test.skip install
Once successful, cd to the runtime's freshly built bin directory under $ARCHIVA_BASE/archiva-plexus-runtime's target:
target/plexus-archiva-runtime/bin/$MY_OS
Where $MY_OS is the operating system you think you're running. Then, execute the run script within it. If you are running windows, you can install Plexus as a service via the win32/InstallService.bat script and will find a new service installed in your Control Panel's Services list. Other operating systems can add the run.sh script as part of its startup routine.

After you have the server running or installed, navigate your web browser of choice to http://localhost:8080. If this is the first time running Archiva, you will be confronted with a screen requesting you to create an admin user. After submission, you will be required to log in as an administrator with that information.

Once you are logged in, you will be required to create at least one managed repository. The Maven standard is to create at least two repositories, one for development SNAPSHOT artifacts, and one for release artifacts. However, you can create as many repositories as you wish, for example testing and staging releases. We recommend giving the URL extensions and identifier the same value, to avoid confusion. Note that you can create a repository of types other than Maven 2, but also Maven 1.

Directory is the absolute path where this repository will place its artifacts. If you are installing on a Windows-based machine, note that since Windows has an upper-limit on directory + file -names, it is best to make the directory fairly short. "Snapshots Included" means just as it sounds - the repository will make snapshots available.

Once you have created a configuration, you need to set up a schedule for when the Archiva repositories will index (it defaults to every 3 minutes), and what directory the index should be held in. I suggest you leave the year field blank (unless you really do want to update only on certain years). The index directory will be relative directory from running directory, or absolute directory if prefixed with / or drive: in Windows. Like the managed repositories, you should enter an absolute directory location that has plenty of disk space.


After the index is set up, you will be shown your settings. This signals the end of required setup.

Now that you have added a managed repository and indexes, you can now proxy any number of remote repositories through that one. For example, we will add Maven Central and the Codehaus Snapshot repositories to be proxied through the Development Repository (snapshot) we created above. The benefit of this practice is three-fold. One, it allows your build manager to control network access to remote repositories locally. Two, it allows a convenient single-access point repository across an organization (you can add any number of proxied repositories, but your user's POMs need only point to the single managed repository). Three, if the proxied repositories are indexed, your builds are not bound to the remote repositories' network access in order to succeed. I am certain there are more.

A list of proxied repositories... the more the merrier.

If you select "Managed Repositories" in the LHS menu, you will be treated to the basic information about the repositories. A nice little feature is if you select "Show POM Snippet" a div will expand revealing the correct values for connecting to the specific repository, as well as information for deploying built artifacts to this repository via WebDAV, which Archiva manages for you.

3 comments:

Victor said...

Excellent post! Thank you for the effort.

Anonymous said...

The Connector jar should now be available from Java.net's Maven Repository: https://maven-repository.dev.java.net/nonav/repository/javax.resource/

georgo said...

I had to add the jta api too:

mvn install:install-file /
-DgroupId=javax.transaction /
-DartifactId=jta -Dversion=1.0.1B /
-Dpackaging=jar /
-Dfile=jta-1_0_1B-classes.zip