maven pom 的存储库元素中 enabled(snapshot, releases) 标签的用途是什么?

What is use of enabled(snapshot, releases) tag in maven pom's repository element?

指定存储库元素时,为什么我们还需要 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-发布)

当有多个存储库时,将在哪个存储库中搜索工件?如何解决工件?

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

例如,如果我们想要一个仅用于发布版本的存储库,而另一个仅用于 SNAPSHOT 版本,则我们需要这样做。

这是企业 Maven 存储库(即 Nexus、Artifactory、Archivia)的常见用例,当某些版本(如 SNAPSHOT)仅在存储库(已部署但 CI 作业,作为示例),而发布的版本只能在另一个存储库中使用。 CI 为 PROD 发布内容的工作应该只使用后一个存储库,而不是 using/allowing 任何 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在工件解析期间不遵守来自 settings.xml 的存储库顺序

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

合并上面的两个答案,具体取决于声明的顺序和哪个存储库允许哪种类型的工件(快照或不允许)。


进一步参考: