maven: what does ` -U,--update-snapshots` really do?

前端 未结 3 1873
深忆病人
深忆病人 2021-02-05 09:09

In the command line help, I see that maven \"checks\" for updates:

-U,--update-snapshots                  Forces a check for updated
                                     


        
相关标签:
3条回答
  • 2021-02-05 09:19

    If you do not use -U, maven might cache results - even if a dependency could not be found (e.g. because you nexus [or alike] was unavailable, misconfigured, didn't contain the dependency [yet] or whatever).

    If that's the case. Maven follows the repository's updatePolicy, which tells it how often (if ever) maven checks if a dependency has been updated. Default is daily therefore if a temp error causes maven to not download a dependency, it might take one day before maven tries again. -U overwrites that and tells it to check now.

    -U does not re-download a dependency if it has already been downloaded and if the checksum is the same! It only checks for the checksum.

    Update: as @Stas pointed out, if the checksum differs, it will re-download and override you local JARs with the ones from the remote repository.

    BTW: Maven uses a timestamp file that has the same name as the dependency + ".lastUpdated" to know when a dependency has been last checked on which server. E.g. ~/.m2/repository/org/springframework/spring-webmvc/3.1.2.RELEASE/spring-webmvc-3.1.2.RELEASE.jar.lastUpdated

    Example for updatePolicy:

    <repositories>
      <repository>
        <releases>
          <enabled>false</enabled>
          <updatePolicy>always</updatePolicy>
        </releases>
        <snapshots>
          <enabled>true</enabled>
          <updatePolicy>never</updatePolicy>
        </snapshots>
        <!-- ... -->
      </repository>
      <!-- ... -->
    </repositories>
    

    See http://maven.apache.org/pom.html#Repositories for further information about the updatePolicy.

    0 讨论(0)
  • 2021-02-05 09:23

    It's important to add that executing mvn -U will override your local SNAPSHOT jars with remote SNAPSHOT jars.

    Without -U argument, local SNAPSHOTS won't be override.

    0 讨论(0)
  • 2021-02-05 09:28

    when you will get https://repo.spring.io/milestone was cached in the local repository, resolution will not be reattempted until the update interval of spring-milestones has elapsed or updates are forced

    in that case you have to use mvn clean package -U

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