Moving Artifacts Between Sonatype Nexus Repositories

April 14, 2010 By Tim OBrien

2 minute read time

While Sonatype Nexus Open Source does not have any UI-level support for moving an artifact between two repositories, you can very easily do this by just manipulating the underlying filesystem and reindexing the two hosted repositories. There are a few reasons you might want to use this functionality, maybe you want to support a promotion strategy between two hosted repositories? If this is something you find yourself doing, my first suggestion is that you consider the Staging functionality available in Sonatype Nexus Professional. If Staging isn't an exact match for your requirements, this post will detail the process you should follow if you need to move an artifact between two repositories.

The process for moving an artifact between two hosted repositories:

1. While logged in as an admin, bring both the source and destination repository to an "Out-of-service" state by navigating to the repositories list, right-clicking on both repositories and selecting "Put out of service" as shown in the following figure.

2. While the repositories are Out of Service, you can manipulate the underlying storage directory. Each hosted repository has a folder under ${sonatype-work}/storage. To move a particular artifact, or collection of artifacts between two repositories, you would simply move the files between these directories.

3. Once this move has been completed, you can put both repositories back into service, by navigating to the repository list, right-clicking on a particular repository, and selecting "Put in Service" as shown below.

4. Since you changed the underlying storage for this repository, you will want to rebuild the repository metadata *and* reindex the repository. You can do both of these using the same process you used to put the repository back in service. Navigate to the repository list, right-click on the repository and select both Rebuild Metadata and Reindex.

There's an Easier Option: Sonatype Nexus Staging

While the method documented in this blog post will work, if you find yourself frequently needing to move artifacts between repositories, you will want to look into Sonatype Nexus Professional. Sonatype Nexus Professional offers a Staging Suite which provides this functionality with an easier and more intuitive interface. While Staging doesn't specifically move artifacts between hosted repositories, it provides for the ability to expose "staged artifacts" in a repository group and to either discard or "promote" an artifact to a hosted repository depending on testing and validation.

Tags: Sonatype, Sonatype Nexus Repository, Sonatype Nexus Repository OSS

Written by Tim OBrien

Tim is a Software Architect with experience in all aspects of software development from project inception to developing scaleable production architectures for large-scale systems during critical, high-risk events such as Black Friday. He has helped many organizations ranging from small startups to Fortune 100 companies take a more strategic approach to adopting and evaluating technology and managing the risks associated with change.