read

I recently needed to move build artifacts from JFrog Artifactory to Sonatype Nexus. But I couldn’t migrate every project in one go and they were all commingled in the same repository.

The first task was to export the existing artifacts using the built-in utility. Start by navigating to the Admin menu and selecting Repositories under the Import & Export section. I used the following settings. Note that excluding the metadata is important here as they are meaningless to Nexus and will just clutter things up.

Export configuration

The next step was to find a way to filter the uploaded artifacts. I started with the mavenimport.sh script by DarthHater but found that it didn’t meet my needs. With that inspiration it was pretty easy to create my own import.sh using the find command.

import.sh takes the following options:

  • -r|--repo-url: the URL of the Nexus repository which the artifacts should be uploaded to.
  • -u|--username: the username of the account on the Nexus server to use when authenticating the upload. If not specified the default value is anonymous.
  • -p|--password: the password of the account on the Nexus server to use when authenticating the upload. If not specified the default value is anonymous.
  • -g|--group: the group whose artifacts will be uploaded. This must be specified in dot separated notation. For example, com.example.group.app.
  • -b|--base-dir: the directory to search in for artifacts. If not specified the default value is $(pwd).

Using this I can now import just the artifacts I want.

cd /tmp/repositories/
wget https://www.steventwheeler.com/assets/article_files/2018-10-30-migrate-artifactory-to-nexus/import.sh
chmod +x import.sh
./import.sh --repo-url https://nexus.example.com/repository/maven-hosted-releases/ --group com.example.myapp --base-dir libs-release-local/
Blog Logo

Steven Wheeler


Published

Image

Steven Wheeler

A repository of things I occasionally need to look up. Hopefully, it helps others save time too.

Back to Overview