Update Nexus repository with local artifacts

12,668

Nexus has several type of repositories: hosted repositories (those that really store maven artifacts), proxy repositories (that redirect traffic to other remote repositories when an artifact is requested), virtual repositories (a mere adapter of maven1 repositories [out of the scope of this question]). you can also create repository groups that can serve artifacts from any of its aggregates (the public repository is one of these).

In addition, nexus divides their repositories according to its publishing policy into snapshots and releases. The former stores only snapshot artifacts; while the latter, in theory, can store both snapshots and releases, but it actually behaves buggy when the repo is very big and contains snapshots.

In order to host your artifacts you need to:

First: Divide your local repository into two: one containing the snapshots, and another containing the releases. Nexus repository convertion tool will help you if your repo is very big:

    <dependency>
        <groupId>org.sonatype.nexus.tools</groupId>
        <artifactId>nexus-repository-conversion-tool</artifactId> 
        <version>1.8.0.1</version>
        <classifier>cli</classifier> 
    </dependency>

Once downlaoded you can just execute java -jar nexus-repository-conversion-tool-1.8.0.1-cli.jar -rSource -oTarget where Source is the directory that contains the local repository to move to nexus, and Target is an existing, empty and writable directory where the convertion tool will leave the splitted repositories. Provided that source directory is repository and Target is temp, it will create temp/repository-snapshots and temp/repository-releases directories.

Second: move your splitted repos to nexus. And leave them in ${NEXUS_HOME}/sonatype-work/nexus/storage, or wherever your nexus installation is configured to store the repositories.

Third: create two hosted repositories with the same id as the repos you moved in the second step. (in the example repository-snapshots and repository-releases)

If your repo would only contained releases, your solution could have worked, but you will have commited another mistake. Although nexus stores artifacts for every repository, the storage of those that aren't hosted repos is just for caching purposes (as in the case of the public repository), you would have to copied your contents to a hosted one in order to work.

Share:
12,668
mamuesstack
Author by

mamuesstack

Updated on July 19, 2022

Comments

  • mamuesstack
    mamuesstack almost 2 years

    i recently downloaded some maven artifacts directly to my local repository (.m2/repository). Now i installed the Nexus Repository Manager and need to fill its storage without to download all the artifacts again. Is there a way to update the Nexus repository with the local one. I don't want to simply copy them because Nexus separate artifacts concerning their public servers (central, codehaus, etc.) and the local repository structure doesn't.

    Update: Meanwhile i copied the the artifacts from the local repository to the Nexus storage (public repository). I can browse to the artifacts via the Nexus webapp, but Maven somehow can't resolve the artifacts from Nexus. Do i need to register them particularly? I re-indexed the public repository and restarted Nexus multiple times - no changes.

  • Miguel
    Miguel over 13 years
    You also have to consider what kind of artifacts are you hosting in your repository. Nexus divides repositories into spanshots and release depending on wether it hosts snapshot artifacts or release + snapshots. Although it sho
  • mamuesstack
    mamuesstack about 13 years
    Oh, I read your answer too late. Your approach would have saved me a lot of time, I guess. I also separated snapshot and release artifacts and then manually moved them to the corresponding Nexus repositories. I somehow had to deploy each release artifact using the cli. For the snapshots it had suffice to re-index the Nexus cache. Thanks!