Guide to relocation

Sometimes it is necessary to relocate artifacts in the repository. One example of that is when a project moves from one groupId to different groupId. Making changes to the repository can have far reaching consequences. So it is best to get it right the first time, hence this guide.

The goal of the examples below is to relocate the groupId from bar to org.bar for the foo project.

How to relocate a Maven 2 artifact to a different groupId

  1. Copy all foo-related files from /bar/foo/ in your Maven 2 repository to a temporary location.
  2. Change the groupId to org.bar in all foo-related pom files in the temporary location.
  3. Copy all files from the temporary location to /org/bar/foo/ in your Maven 2 repository.
  4. Create a minimal Maven 2 pom file for every old release of foo in your Maven 2 repository. The pom files only need to include groupId, artifactId, version and the relocation section.

    Note: Before you replace your old pom files in /bar/foo/ with these minimal pom files, make sure you have made backups!

    The minimal pom file might look like this for version 1.0 of foo:

    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>bar</groupId>
      <artifactId>foo</artifactId>
      <version>1.0</version>
      <distributionManagement>
        <relocation>
          <groupId>org.bar</groupId>
        </relocation>
      </distributionManagement>
    </project>

    In this case we are relocating because the groupId has changed. We only need to add the element that has changed to the relocation element. For information on which elements are allowed in the relocation element, see the pom reference.

  5. If your project uses MD5 or SHA1 checksums you must now create new checksums for the pom files in /bar/foo/ in your Maven 2 repository. If the pom file needs to be signed, do that as well.
  6. If your project syncs with Central, you should now initiate that sync. This might happen automatically depending on your projects sync policy.

Your foo-artifacts are now available to Maven users with both the old and the new groupId. Projects using the old groupId will automatically be redirected to the new groupId and a warning telling the user to update their dependencies will be issued.

Releasing the next version

When the next release of foo is made, you should publish two Maven 2 pom files. First you should publish a pom with the new groupId org.bar.

Because data in the repository is not supposed to change, Maven doesn't download pom files that it has already downloaded. Therefore you will also need to publish a pom file with the old groupId bar for the new version. This should be a minimal relocation pom (as described in step 4 above), but for the new version of foo.

For the release after that, you only need to publish a Maven pom with a groupId of org.bar, since users of the previous version have been informed of the changed groupId.