When migrating a project I needed to move dependencies from one maven repository to another. The new repository is a Nexus 3 repository which has no import or export functionality, automated or manual (yet). The project being migrated uses a lot of dependencies. The easy way would be to just proxy the old repository in the new one and get on with the job. This time that wasn’t an option and I had to make do with a copy of a local maven repository (.m2 directory). As it turns out there is a nice tool called Maven Repository Provisioner, which can be used to import artifacts into a maven repository. As a bonus it can also import from a local maven repository on disk, just what I was looking for.
Maven Repository Provisioner
After downloading the most recent release, currently 1.2.1, you can provision a maven repository from a local maven repository you can run the following command:
$ java - jar maven-repository-provisioner-1.2.1-jar-with-dependencies.jar -cd <path/to/local/repository> -t "http://localhost:8081/repository/maven-releases" -u <user> -p <password>
The maven repository provisioner will now scan the local maven repository and upload all found artifacts to the specified repository. You just need to make sure the local repository contains only maven meta data. If there is other information stored it will get imported as artifacts into the repository. You probably do not want that.
If you do have access to a source repository you can use the following command to extract the needed artifacts and upload them to the new repository.
$ java - jar maven-repository-provisioner-1.2.1-jar-with-dependencies.jar -a "org.apache.commons:commons-lang3:jar:3.3.2|junit:junit:4.11" -t "http://localhost:8081/repository/maven-releases" -u <user> -p <password> -s "<source-repository>"
-a flag specifies the artifacts that are being imported. The format for
group:artifact[:extension][:classifier]:v. You can supply multiple artifacts by separating them with a
If you do not specify the
-a flag ALL artifacts found will be uploaded to the target repository. This can be a lot if you are using maven central as a source repository.