专家:`-U,-update-snapshots`到底有什么作用? [英] maven: what does ` -U,--update-snapshots` really do?

查看:1327
本文介绍了专家:`-U,-update-snapshots`到底有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在命令行帮助中,我看到maven检查"了更新:

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

但是,有关堆栈溢出的大多数问题都暗示此选项会强制Maven更新.这是否意味着必须重新下载依赖项?

例如 https://stackoverflow.com/a/9697970/1119779

解决方案

如果您不使用-U,即使找不到依赖项,maven也会缓存结果-例如,由于您的联系[或类似原因]不可用,配置错误,不包含依赖项[yet]或其他任何内容.

如果是这种情况. Maven遵循存储库的updatePolicy,它告诉它maven多久(如果有的话)检查依赖项是否已更新.默认值为daily,因此,如果临时错误导致maven不下载依赖项,则可能需要一天时间才能再次尝试. -U覆盖并告诉它立即检查.

-U如果已下载依赖项并且校验和相同,则不会重新下载依赖项!它仅检查校验和.

更新:如@Stas所指出的那样,如果校验和不同,它将重新下载本地JAR并用远程存储库中的JAR覆盖. >

BTW:Maven使用与依赖项+ ".lastUpdated"同名的时间戳文件来了解何时在哪个服务器上最后一次检查了依赖项.例如. ~/.m2/repository/org/springframework/spring-webmvc/3.1.2.RELEASE/spring-webmvc-3.1.2.RELEASE.jar.lastUpdated

updatePolicy示例:

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

请参见 http://maven.apache.org/pom.html#Repositories 了解有关updatePolicy的更多信息.

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

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

However, most questions on Stack Overflow imply that this option forces Maven to update. Does this mean it forces a re-download of the dependencies?

e.g. https://stackoverflow.com/a/9697970/1119779

解决方案

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.

这篇关于专家:`-U,-update-snapshots`到底有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆