maven - maven pom 的存储库元素中启用(快照、发布)标签有什么用?

标签 maven maven-3 pom.xml

当指定存储库元素时,我们为什么需要 snapshotsreleases还有?
例子:

<repository>
  <id>my-repo</id>
  <url>https://some.url.com/my-repo</url>
  <snapshots>
    <enabled>false/true</enabled>
  </snapshots>
  <releases>
    <enabled>false/true</enabled>
  </releases>
</repository>
它如何影响依赖项的特定版本? (1.2.3-快照、1.2.3、1.2.3-发布)
当有多个存储库时,会在哪个存储库中搜索 Artifact ?神器是如何解决的?

最佳答案

When specifying the repository element why we need false/true and as well?


例如,如果我们希望有一个仅用于已发布版本的存储库,而另一个仅用于 SNAPSHOT 版本的存储库,则需要这样做。
这是企业 Maven 存储库(即 Nexus、Artifactory、Archivia)的常见用例,当某些版本(如 SNAPSHOT)仅在存储库中可用(例如已部署但 CI 作业)而发布版本仅可用在另一个存储库中。为 PROD 发布某些内容的 CI 作业应该只使用后一个存储库,而不是使用/允许任何 SNAPSHOT 版本,否则会破坏构建(强制构建可重现性和良好实践)。
来自 official Maven Settings documentation

releases, snapshots: These are the policies for each type of artifact, Release or snapshot. With these two sets, a POM has the power to alter the policies for each type independent of the other within a single repository. For example, one may decide to enable only snapshot downloads, possibly for development purposes.

enabled: true or false for whether this repository is enabled for the respective type (releases or snapshots).



When there are multiple repositories , which repository will be searched for the artifact? How the artifacts being resolved?


声明的顺序会影响Maven使用的查找顺序。检查这个 official Maven ticket为版本 中的正确行为提供修复3.0 在。
  • MNG-4400 : Artifact 解析期间不遵守 settings.xml 中的存储库顺序

  • How it affects a specific version of the dependency? (1.2.3-SNAPSHOT, 1.2.3, 1.2.3-RELEASE)


    合并上面的两个答案,取决于声明的顺序和哪个存储库允许哪种类型的 Artifact (快照与否)。

    进一步引用:
  • Maven: working with multiple repositories
  • Maven Settings
  • Maven: introduction to repositories
  • 关于maven - maven pom 的存储库元素中启用(快照、发布)标签有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36177635/

    相关文章:

    java - 使用 Maven 和 Jersey/Jackson 设置生成的依赖于平台的 .war 文件?

    java - 使用 Jenkins 将二进制文件与 JAR 文件一起发布到 Maven Artifact

    java - Maven 对所有项目使用相同的 API 文档(mvn 站点定制)

    Eclipse Indigo 缺少 POM 编辑器首选项

    java - 编译错误,从命令行在 maven 项目中运行 Selenium 测试时

    java - 将 lzo 文件作为数据集导入 java Spark

    java - jfxrt.jar 包含在 Java 8 中吗?

    使用 surefire-report-plugin 的 Maven 多模块项目应该生成聚合报告

    Maven - 依赖管理中的多个 Artifact 版本

    java - 找不到 org.codehaus.mojo