maven 不拉取 snapshot 问题

默认情况下,maven 只会拉取 release 版本的依赖,通常情况下下不会有问题,但是如果公司 maven 有自己的 snapshot 依赖,那就没办法拉取了。 需要在setting.xml中加入一些配置来支持 snapshot 拉取。示例如下: 注意:通常 snapshot 的 url 地址和 release 的 url 地址是不一样的,需要分别配置

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">

  <localRepository>D:/program/apache-maven-3.8.2/mvnRep</localRepository>

  <pluginGroups>

  </pluginGroups>


  <proxies>
  </proxies>


  <servers>
  </servers>

  <mirrors>
    <mirror>
      <id>central</id>
      <mirrorOf>*</mirrorOf>
      <url>http://xxxxxx/artifactory/group/</url>
      <name>group</name>
    </mirror>

    <mirror>
      <id>snap</id>
      <mirrorOf>public-snapshots</mirrorOf>
      <url>http://xxxxxx/artifactory/shareSnapshot/</url>
      <name>snap</name>
    </mirror>
  </mirrors>

  <profiles>
    <profile>
      <id>public-snapshots</id>
      <repositories>
        <repository>
          <id>nexus_snapshot_repository</id>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
          <url>http://xxxxxx.com/artifactory/shareSnapshot/</url>
          <layout>default</layout>
        </repository>

      </repositories>

      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://xxxxxx/artifactory/group/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
          <updatePolicy>always</updatePolicy>
        </pluginRepository>
      </pluginRepositories>

    </profile>

  </profiles>

  <activeProfiles>
    <activeProfile>public-snapshots</activeProfile>
  </activeProfiles>
</settings>

snapshot 依赖更新问题

默认情况下 snapshot 并不会每次检查更新,如果一天发布了多个 snapshot,可能会无法获取到最新的。这里提供三种方式实现每次更新依赖检查 snapshot 更新情况。

添加-U 参数

使用 maven 命令时,追加一个-U,例如:

mvn clean package/install/deploy -U

修改 idea 配置

勾选Always update snapshots

修改 maven 配置

修改 settings.xml,在 repository 和 pluginRepository 下配置总是更新 Maven snapshots 依赖:

          <snapshots>
            <updatePolicy>always</updatePolicy>
          </snapshots>