Migrating from nexus 1.x to 3.x

If you google "migrating to nexus 3" you'll find a bunch of links that suggest an easy peasy way to migrate from Nexus 2 to 3. But this wasn't my case :/ The client has a nexus 1.9 on the server (too old! I know), and from here starts a long journey.

Installing nexus 3.x is a one command thing, so no need to talk about it. But what happen when you want to migrate your data from the old nexus to the new one?! well there's no obvious solution!

You should probably know that Nexus 1.x stores Maven artifacts directly in file system, according Maven coordinate tree (com/sun/xml/...), but version 3.0.2 stores artifacts in elasticsearch repo, as blob objects.

to solve this issue I wrote a small script that upload artifacts into Nexus, which basically send a HTTP PUT of a file into /repository/<repo-id>/<path-of-file>:


  EXTENSIONS="*.jar *.war *.pom *.xml *.md5 *.sha1 *.zip"

  for tosearch in $EXTENSIONS;
       for file in `find . -name $tosearch`;
           echo "uploading path $path"
           curl -u <username>:<password> --upload-file $path http://<my.sonar.url>:<port>/repository/$REPOSITORY/$path

et Voila! now all the artifacts that we had on our old nexus server, are now on Nexus 3!

Source: https://support.sonatype.com/hc/en-us/articles/213465818-How-can-I-programmatically-upload-an-artifact-into-Nexus-2-