How to register a custom Maven repository layout

Maven repositories have a defined directory layout. In the standard installation Maven comes with 2 implementations, the default layout for Maven 2 and legacy layout for Maven 1.x. The layout is configured in the repository setting either in POMs or settings.xml file.

          <name>Codehaus Snapshots</name>

Normally the default structure is sufficient, but if what to do if forever which reason the layout should be changed? Basically what needs to be done is to provide an implementation of the ArtifactRepositoryLayout interface, register the implementation to Maven and configure repositories with a custom layout identifier, e.g.

The Maven core is extensible, based on the Plexus IoC container. Plexus components are configured in META-INF/plexus/components.xml. Component implementations are looked up from the Plexus container with a key identified by role and optionally role-hint. A components.xml with a custom ArtifactRepositoryLayout looks like this:


The role-hint value is the identifier that is matched with the repository’s <layout> configuration.

Let’s assume a project artifact should be deployed to a Maven repository with custom layout. The corresponding section in the pom.xml file is for example:


Without proper setup a “mvn deploy” would fail with exception:
mvn deploy
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: com.itemis.example.maven:custom-repository-test
POM Location: /Users/thoms/Development/workspaces/sandbox-jsf/custom-repository-test/pom.xml
Reason: Cannot find layout implementation corresponding to: 'custom' for remote repository with id: 'testrepo.snapshot'. for project com.itemis.example.maven:custom-repository-test at /Users/thoms/Development/workspaces/sandbox-jsf/custom-repository-test/pom.xml

The jar with the custom layout implementation has to be deployed to $MAVEN_HOME/lib (on my machine /usr/share/maven/lib for example). All libraries from that directory are automatically included. It might be necessary to adjust $MAVEN_HOME/bin/m2.conf and add the following section and put the jar containing the custom repository layout implementation into a custom folder:
load ${maven.home}/custom/*.jar

After doing so a deployment should be successful and use the customized layout:

> mvn deploy
[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from testrepo.snapshot
Uploading: /tmp/repository/com/itemis/example/maven/1.0.0-SNAPSHOT/custom-repository-test/custom-repository-test-1.0.0-20091013.164125-2.jar

The custom implementation here changes the order of the base version and artifact id in the repository layout structure. The normal Maven2 repository structure is groupId/artifactId/version, this here uses groupId/version/artifactId. The sourcecode for this example can be downloaded here.

Speaking at W-JAX 09

wjax09_button_speaker_enMy colleague Heiko Behrens and I will have a session at the upcoming W-JAX conference.
The session is entitled “Mastering differentiated MDSD Requirements at Deutsche Boerse AG“, and we will share our experience about successfully applying MDSD approaches that we gained through our consulting tasks at the Deutsche Boerse. The project at the Deutsche Boerse is in many ways challenging and a great example how model driven software development really helps to master complexity. The Deutsche Boerse is developing together with the New York ISE a new Global Trading System (GTS), which is scheduled to start operations in 2011. High performance and reliability is crucial for this system, and it would not be possible to deliver both without means of modeling and code generation. Of course we leverageEclipse Modeling and openArchitectureWare for that. We held this session already at the Code Generation 2009 with overwhealming feedback, and in the meantime the story continued and we will include the new experiences into our talk.