localRepository机制:

  • introduction-to-repositories
    The local repository refers to a copy on your own installation that is a cache of the remote downloads, and also contains the temporary build artifacts that you have not yet released.

  • settings.xml配置:

    /path/to/local/repo

  • 使用场景:

    • maven执行编译打包时先进行依赖的下载:
    • 如果项目依赖localRepository中已经存在,那么继续进行编译打包;
    • 如果项目依赖localRepository中不存在,那么先下载依赖到localRepository,然后进行编译打包;

强制更新SNAPSHOT版本依赖:

  • snapshots updatePolicy
    • updatePolicy: This element specifies how often updates should attempt to occur. Maven will compare the local POM’s timestamp (stored in a repository’s maven-metadata file) to the remote. The choices are: always, daily (default), interval:X (where X is an integer in minutes) or never.
  • 👇场景下需要强制更新:
    • 默认snapshot版本依赖localRepository更新是天级的。如果项目联调阶段一天之内多次snapshot依赖更新。

    • 如果项目下载依赖过程中断(常见网络原因),导致localRepository中的文件状态有问题。

      mvn clean package -U

      -U,–update-snapshots
      Forces a check for missing releases and updated snapshots on remote repositories

强制更新RELEASE和SNAPSHOT版本依赖:

  • 👇场景建议使用强制更新:

    • 如果项目下载依赖过程中断(常见网络原因),导致localRepository中的文件状态有问题。
  • 方法:

    • 简单粗暴型:直接清空localRepository,然后执行编译打包重新下载依赖。

    • 推荐精细型:定向删除localRepository中 本次项目涉及依赖,然后重新下载:

      mvn dependency:purge-local-repository

        tells Maven to clear all dependency-artifact files out of the local repository, and optionally re-resolve them.