美文网首页
Maven下载Release包失败问题复盘

Maven下载Release包失败问题复盘

作者: 一周一志 | 来源:发表于2024-07-16 16:59 被阅读0次

    ## Maven下载Release包失败问题复盘

    ### 问题描述

    我在建立maven 私服时,在尝试从Nexus仓库下载Maven项目的Release包时,遇到了以下错误:看好下载状态 Downloading、Downloaded.

    ```plaintext

    Downloading from daoxiu-releases: http://192.168.1.17:8081/repository/maven-release/org/daoxiu/common-service/1.0.2/common-service-1.0.2.pom

    Downloading from nexus-mine: http://192.168.1.17:8081/repository/maven-public/org/daoxiu/common-service/1.0.2/common-service-1.0.2.pom

    ==Downloaded== from nexus-mine: http://192.168.1.17:8081/repository/maven-public/org/daoxiu/common-service/1.0.2/common-service-1.0.2.pom (1.8 kB at 21 kB/s)

    Downloading from daoxiu-releases: http://192.168.1.17:8081/repository/maven-release/org/daoxiu/common-service/1.0.2/common-service-1.0.2.jar

    Downloading from nexus-mine: http://192.168.1.17:8081/repository/maven-public/org/daoxiu/common-service/1.0.2/common-service-1.0.2.jar

    Downloaded from nexus-mine: http://192.168.1.17:8081/repository/maven-public/org/daoxiu/common-service/1.0.2/common-service-1.0.2.jar (2.4 kB at 37 kB/s)

    [INFO]

    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ order-service ---

    [INFO] Using 'UTF-8' encoding to copy filtered resources.

    [INFO] Copying 0 resource

    [INFO]

    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ order-service ---

    [INFO] Nothing to compile - all classes are up to date

    [INFO] ------------------------------------------------------------------------

    [INFO] Reactor Summary:

    [INFO]

    [INFO] micro-shop 1.0-SNAPSHOT ............................ SUCCESS [  0.001 s]

    [INFO] user-service ....................................... SUCCESS [  0.295 s]

    [INFO] commons-service 1.1.0 .............................. SUCCESS [  0.014 s]

    [INFO] order-service 1.0.1-SNAPSHOT ....................... SUCCESS [  0.322 s]

    [INFO] ------------------------------------------------------------------------

    [INFO] BUILD SUCCESS

    [INFO] ------------------------------------------------------------------------

    [INFO] Total time: 0.678 s

    [INFO] Finished at: 2024-07-16T09:46:00+08:00

    [INFO] ------------------------------------------------------------------------

    Process finished with exit code 0

    ```

    **BUILD SUCCESS!**

    到这里我以为大功告成的时候,无意间看了一下加载顺序地址。

    嘿!哦?!

    包能下载了,但是仔细一看发现一个问题,包都是从/repository/maven-public 下载成功的。

    但是我配置了是release仓库 角色权限和账号daoxiu-releases,每次虽然都有请求到 /repository/maven-release 状态是Downloading,但是能看到最终成功的都是从maven-public仓库中Downloaded下载成功的。

    可以从请求日志中看到每次都是有请求这个地址 http://192.168.1.17:8081/repository/maven-release/org/daoxiu的,但是就是没有一个包是从这里下载下来的,最终都是从http://192.168.1.17:8081/repository/maven-public/ 拉下来的包。

    ### 经验分析:

    1、加载优先级的问题?

    2、daoxiu-releases账号权限的问题?

    3、这个版本的jar包不存在仓库中

    ### 排查原因分析

    **首先**排除 3

    我确认这个包common-service-1.0.2.jar 的确存在。

    <img src="/Users/zhizhou/Documents/学管理/写作/图片/image-20240716103754451.png" alt="image-20240716103754451" style="zoom:30%;" />

    **再次**

    排除2, 判断错误是由于权限配置问题,索性给`daoxiu-releases`  用户赋予了nx-all Privileges。还是不行。

    **最后**

    索性将加载地址拷贝出来,在浏览器查看。奇怪一个200,一个404。我丢,再细细思量,一看404 包名称写错了,少了个“s”即 `maven-releases` 而非 `maven-release`,我xxxx。

    ```

    httpcode:200

    http://192.168.1.17:8081/repository/maven-release/org/daoxiu/common-service/1.0.2/common-service-1.0.2.jar

    httpcode:404

    http://192.168.1.17:8081/repository/maven-release/org/daoxiu/common-service/1.0.2/common-service-1.0.2.jar

    ```

    但最终发现实际原因是仓库地址配置错误。正确的仓库地址应该是:

    - `daoxiu-releases`: `http://192.168.1.17:8081/repository/maven-releases/`

    - `nexus-mine`: `http://192.168.1.17:8081/repository/maven-public/`

    由于地址错误,Maven无法从`daoxiu-releases`下载Release包,而是从`nexus-mine`下载了POM和JAR文件。

    ### 解决步骤

    #### 1. 检查并更新仓库配置

    确保在`pom.xml`文件中正确配置仓库地址:

    ```xml

    <repositories>

        <repository>

            <id>daoxiu-releases</id>

            <url>http://192.168.1.17:8081/repository/maven-releases/</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

        </repository>

        <repository>

            <id>nexus-mine</id>

            <url>http://192.168.1.17:8081/repository/maven-public/</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>true</enabled>

            </snapshots>

        </repository>

    </repositories>

    ```

    确保在`settings.xml`文件中正确配置服务器认证信息:

    ```xml

    <servers>

        <server>

            <id>daoxiu-releases</id>

            <username>your-username</username>

            <password>your-password</password>

        </server>

        <server>

            <id>nexus-mine</id>

            <username>your-username</username>

            <password>your-password</password>

        </server>

    </servers>

    ```

    #### 2. 清理Maven缓存并重新构建

    执行以下命令清理Maven缓存并重新构建项目:

    ```sh

    mvn clean install -U

    ```

    #### 3. 验证下载过程

    重新运行Maven构建命令,确认依赖包从正确的仓库下载:

    ```sh

    mvn clean install

    ```

    执行顺序日志,这里就是从repository/maven-releases下载包了。

    ```bash

    [INFO] ----------------------< org.forsx:order-service >-----------------------

    [INFO] Building order-service 1.0.1-SNAPSHOT                              [4/4]

    [INFO] --------------------------------[ war ]---------------------------------

    Downloading from daoxiu-releases: http://192.168.1.17:8081/repository/maven-releases/org/daoxiu/common-service/1.0.2/common-service-1.0.2.pom

    Downloaded from daoxiu-releases: http://192.168.1.17:8081/repository/maven-releases/org/daoxiu/common-service/1.0.2/common-service-1.0.2.pom (1.8 kB at 19 kB/s)

    Downloading from daoxiu-releases: http://192.168.1.17:8081/repository/maven-releases/org/daoxiu/common-service/1.0.2/common-service-1.0.2.jar

    Downloaded from daoxiu-releases: http://192.168.1.17:8081/repository/maven-releases/org/daoxiu/common-service/1.0.2/common-service-1.0.2.jar (2.4 kB at 39 kB/s)

    [INFO]

    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ order-service ---

    [INFO] Using 'UTF-8' encoding to copy filtered resources.

    [INFO] Copying 0 resource

    ```

    ### 结论

    通过检查和更新Maven仓库地址配置,成功解决了无法下载Release包的问题。确保仓库配置正确,尤其是URL地址的准确性,对于Maven依赖管理至关重要。个人实操记录,这是一份没有营养的复盘,不该存在的复盘记录。

    ---

    这里是对之前问题的复盘文档,涵盖了问题描述、解决步骤和结论。希望这个复盘文档可以帮助你和团队在未来遇到类似问题时快速定位并解决问题。

    相关文章

      网友评论

          本文标题:Maven下载Release包失败问题复盘

          本文链接:https://www.haomeiwen.com/subject/eqbkhjtx.html