在pom的maven存储库条目中,默认情况下是否启用快照? [英] In a maven repository entry in the pom, are snapshots enabled by default?
问题描述
maven pom可以定义一个存储库",例如:
< repositories><存储库>< id>中央</id><名称>中央存储库</名称>< url> https://repo.maven.apache.org/maven2</url>< layout>默认</layout>< snapshots>< enabled> false</enabled></snapshots></存储库></存储库>
如果我未声明< snapshots>
或< releases>
,该怎么办?它们似乎是可选的...
根据
话虽如此,我建议我们设置它,以便其他开发人员可以了解"为什么未从人工制品中下载其 snapshot
jar的原因.它提供了更多的清晰度,并且考虑到它除了在代码库中没有公开之外,因此不会伤害"任何人.
A maven pom may define a "repository" ex:
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
What if I don't declare <snapshots>
or <releases>
, what are the defaults? They seem optional...
According to https://blog.packagecloud.io/eng/2017/03/09/how-does-a-maven-repository-work/
<releases>
is enabled by default on all repositories. I assume <snapshots>
is disabled by default? So the above snippet is redundant?
EDIT: Added more detail as the answer is a bit complex
TL;DR: Yes, snapshots enabled by default if we configure a <repository>
in pom.xml
If we think through, even when we don't specify any <repository>
in our pom.xml
file, Maven downloads the artifacts from the default repository. This is because the default 'Central' repository is configured in the Super POM.
An excerpt from Super POM's page:
Similar to the inheritance of objects in object oriented programming, POMs that extend a parent POM inherit certain values from that parent. Moreover, just as Java objects ultimately inherit from java.lang.Object, all Project Object Models inherit from a base Super POM. The snippet below is the Super POM for Maven 3.5.4.
<repository> <id>central</id> <name>Central Repository</name> <url>https://repo.maven.apache.org/maven2</url> <layout>default</layout> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> ```
Because of this configuration, snapshot
downloads 'by default' only 'from central maven repository' are disabled.
But if we specify <repository>
in our pom.xml
, then by default the snapshots
are enabled
. You can find the default value of enabled
as true
here:
All that being said, I recommend we set that so that other developers would 'get' why their snapshot
jar is not downloaded from the artifactory. It provides more clarity and given that it's not exposed other than in the codebase, it doesn't 'harm' anyone.
这篇关于在pom的maven存储库条目中,默认情况下是否启用快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!