当指定存储库元素时,我们为什么需要 snapshots
和 releases
还有?
例子:
<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
orfalse
for whether this repository is enabled for the respective type (releases
orsnapshots
).
When there are multiple repositories , which repository will be searched for the artifact? How the artifacts being resolved?
声明的顺序会影响Maven使用的查找顺序。检查这个 official Maven ticket为版本 中的正确行为提供修复3.0 在。
How it affects a specific version of the dependency? (1.2.3-SNAPSHOT, 1.2.3, 1.2.3-RELEASE)
合并上面的两个答案,取决于声明的顺序和哪个存储库允许哪种类型的 Artifact (快照与否)。
进一步引用:
关于maven - maven pom 的存储库元素中启用(快照、发布)标签有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36177635/