Skip to content
Advertisement

In a Maven repository entry in the POM, are snapshots enabled by default?

A Maven POM may define a “repository”. For example,

  <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 How does a Maven repository work?

<releases> is enabled by default on all repositories. I assume <snapshots> is disabled by default? So is the above snippet redundant?

Advertisement

Answer

TL;DR: Yes, snapshots are 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 the 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:

Enter image description here

All that being said, I recommend we set that so that other developers would ‘get’ why their snapshot JAR file is not downloaded from Artifactory. It provides more clarity and given that it’s not exposed other than in the codebase, it doesn’t ‘harm’ anyone.

Advertisement