Maven Snapshot Dependencies Caching


Maven snapshot versions represent a Maven package under active development that can change. By default, the Artifact Cache doesn’t cache snapshot dependencies to avoid storing a large number of constantly changing artifacts. However, depending on your snapshot update frequency, caching them can be beneficial to avoid unnecessary downloads of the same snapshot artifacts in ephemeral CI environments.

Update Policy of Snapshot Dependencies

Before downloading the snapshot JAR, Maven downloads the associated maven-metadata.xml file to determine whether a locally present version of a snapshot artifact is up-to-date. The frequency with which Maven checks for updates is controlled by the updatePolicy setting in your settings.xml file. The available values are:

  • daily (default) - check for updates once per day.

  • always - check for updates on every build. This update policy is similar to running Maven with the -U/--update-snapshots option.

  • interval:XXX - check for updates every XXX minutes.

  • never - download a new version only if the artifact isn’t present locally.

In an ephemeral CI environment, missing snapshot artifacts and metadata will cause the up-to-date check to fail and snapshot artifacts to be downloaded on every build regardless of the configured update policy. By restoring both the metadata and snapshot artifacts, the Artifact Cache allows Maven to perform the up-to-date check and avoid unnecessary downloads of the already available snapshot artifacts.

Configuring Snapshot Dependencies Caching

Caching snapshot dependencies is beneficial only if your snapshot artifacts are stable enough to be reused across builds. If you rely on snapshot artifacts that change frequently, caching them won’t result in any performance improvement and will cause stale snapshot artifacts to accumulate in the Edge node storage until a cleanup is performed.

To enable caching of snapshot dependencies, add the --include-snapshot-dependencies option to the store command of the Artifact Cache CLI. Additionally, consider configuring the updatePolicy setting in your Maven settings.xml file depending on how frequently you want updates to the snapshot artifacts to be visible to the builds.

The current version of Artifact Cache updates the maven-metadata.xml file for the associated snapshot artifact only when a new version of the artifact is downloaded. This can cause Maven to perform the up-to-date checks more frequently than specified in your updatePolicy setting. However, the snapshot artifacts will be re-downloaded only if there is a newer version available, so the performance impact of this behavior is minimal.