I'm trying to migrate my build packages from our on-premise Nexus Repository Manager to Azure Artifacts. I have found this Microsoft link explaining how to do it for NuGet (a .NET package manager) with a Powershell script, but there is no such tool for Maven.
I was thinking about retrieving all the build files with a "maven clean compile" and then pointing my pom.xml file to Azure Artifacts and then somehow push them. However, the amount of packages run into the 100k and there are many applications using it. So this feels like a very clunky way of going about it that will take a lot of effort and a lot of room for error.
Does anyone have any advice for me?
I spent a long time searching for an answer to this question, I even gave up and concluded MS does not support migration from another product!
But it seems this a case of the wrong question to the right problem. The right question is “how do I publish external libraries to Azure Artifacts” - if you can do that, you can upload any artifact.
The solution below transfers the artifacts via your local .m2 repository, so you’ll need a working development environment (Maven installed, project checked out, etc).
I have migrated from Artifactory, but the same process should work for Nexus.
1. Get your pom connected to your existing repository manager and Azure Artifacts.
Your pom should already have an entry to download artifacts from your existing repository manager.
Add a connection to Azure Artifacts in the distribution management.

The instructions in DevOps miss out a key step.
Maven needs Azure’s SSL certificate to make the https connection.
Follow these instructions to download the .crt file from Azure and import into Java’s keystore so that Maven can use it.
The repositories and distributionManagement sections of your pom should look something like this:
<repositories>
<repository>
<id>artifactory</id>
<url>https://my_company/artifactory/libs-release</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>my_project</id>
<url>https://pkgs.dev.azure.com/my_company/my_project/_packaging/my_project/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</distributionManagement>
NOTE: If you have an entry for Azure Artifacts in the repositories section, there's no need to remove it. I've not shown it here because it's not necessary for migration.
2. Download artifacts from your existing repository manager to your local .m2/repository folder.
Run the following command in your project’s root folder, changing the group id and artifact id to match your project:
mvn dependency:get -DgroupId='com.my_company' -DartifactId='my_project' -Dversion='0.1'
You’ll need to cycle through all the version numbers. I used a macro in a text editor to generate a list of commands, or you could use a sh/bat script.
3. Upload these artifacts to Azure Artifacts.
Run the following command in your project’s root folder, changing the path to your .m2 folder, the repository id, url, group id and artifact id to match your project:
mvn org.apache.maven.plugins:maven-deploy-plugin:2.4:deploy-file -Dpackaging=jar -DrepositoryId='my_project' -Durl=https://pkgs.dev.azure.com/my_company/my_project/_packaging/my_project/maven/v1 -DgroupId='com.pd4ml.utilities' -DartifactId='pd4ml' -Dversion='1.0' -Dfile=C:\Users\Steve\.m2\repository\com\pd4ml\utilities\pd4ml\1.0\pd4ml-1.0.jar -DpomFile=C:\Users\Steve\.m2\repository\com\pd4ml\utilities\pd4ml\1.0\pd4ml-1.0.pom
Again, you’ll need to cycle through all the version numbers.
When this is done you’ll see just one(!) artifact in your feed in Azure. Don’t panic, Azure shows only the latest version for each artifact id.
If you click the name of the package and then navigate to “Versions” you’ll see all the versions of this artifact.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With