14

I have a maven project with a snapshot dependency. How does maven know if the snapshot needs to be updated? Does it always update? Is it time based? A checksum based update? I know I can force an update but otherwise, how does it check?

thanks, Jeff

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406

2 Answers2

20

According to the docs, the default is that it will only update once a day. That is when the first build of the day is executed. You can override this behavior with the snapshot-policy element.

  • always - always check when Maven is started for newer versions of snapshots
  • never - never check for newer remote versions. Once off manual updates can be performed.
  • daily (default) - check on the first run of the day (local time)
  • interval:XXX - check every XXX minutes

http://maven.apache.org/maven-settings/settings.html

metatechbe
  • 657
  • 9
  • 9
Christophe Herreman
  • 15,895
  • 9
  • 58
  • 86
  • 6
    This link is a bit dated - I'd try http://maven.apache.org/settings.html#Repositories, and search for updatePolicy – Roy Truelove Jul 07 '11 at 16:18
  • @RoyTruelove true, but that doesn't really help. Here's the most pertinent line on that page: "This element specifies how often updates should attempt to occur. Maven will compare the local POM’s timestamp (stored in a repository’s maven-metadata file) to the remote." As to what that exactly means, it beats me. Does it do it on the first run of the day? or does it do it 24 hours from the last download? – Noremac Aug 12 '14 at 17:53
  • if using m2e plugin, right click on the project --> maven---> update project--> select force update of snapshot/releases will do the trick – Junchen Liu Jun 26 '15 at 10:32
  • or mvn clean install -U . -U means force update snapshots and releases – Junchen Liu Jun 26 '15 at 10:34
8

I have a maven project with a snapshot dependency. How does maven know if the snapshot needs to be updated?

Maven will compare the local POM's timestamp (stored in a repository's maven-metadata file) to the remote. See for example hibernate-core-3.5.0-SNAPSHOT in JBoss snapshots repository.

Does it always update? Is it time based? A checksum based update?

This depends on the updatePolicy of the repository or pluginRepository containing the snapshots. The default is a daily check (other possibles values are always, interval:X (where X is an integer in minutes) or never.

When you use SNAPSHOT internally for a project under active development, it is very common to set the <updatePolicy>always</updatePolicy> for the internal repository.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • But if you are working on project b which depends on a-snapshot, and you're also working on a, downloading a snapshot of a will override your own changes – Asaf Mesika May 26 '11 at 15:41
  • @AsafMesika That is true, m2 plugin for the eclipse has a feature "workspace resolution", which downloads new SNAPSHOTS only for projects the AREN'T open in eclipse workspace. Cook thing, I still haven't found similar netbeans solution – bbaja42 Sep 28 '11 at 08:12