Update Nexus repository with local artifacts

前端 未结 1 1257

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

相关标签:
1条回答
  • 2021-02-04 13:06

    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.

    0 讨论(0)
提交回复
热议问题