SNAPSHOTs are a confusing Maven concept. Maven is a pre-historic build tool, invented inside The Apache Software Foundation to build its (mostly Java) projects back in the 2000s. It is, thus, very opinionated, just like this post. Those opinions — including SNAPSHOTs, maven-release-plugin
, POM, repository and project layouts, and many more — are still alive today and spoil modern projects.
Even ASF does not use Maven to build some of its projects anymore: Beam, Groovy, Lucene, Geode, POI, and Solr are not built with Maven. Those are not the most popular ASF projects, I know, but still, it is something.
Artifacts must be immutable, and two artifacts with the same version must be the same. That is not the case with SNAPSHOTs: they are mutable by definition and every new build could change the artifact published under the -SNAPSHOT
version.
Because of that, SNAPSHOT
artifacts require special treatment. They have their own updatePolicy
. Do you, fellow Maven users, know off the top of your head, how often are they updated by default? Daily. SNAPSHOTs are usually uploaded to a separate repository and they are not — obviously — accepted by the Maven Central.
SNAPSHOTs are a potential source of errors. Hopefully, only during the development and testing process, because no one should use them in production.
Stick to something like Semantic Versioning, and use pre-release identifiers and unique build identifiers instead of SNAPSHOTs. BTW, "SNAPSHOT" is a valid Semver pre-release identifier, however to guarantee artifact immutability, you should include additional metadata in the version, like unique build number, commit hash, or timestamp, etc.
Abandoning SNAPSHOTs doesn’t mean that you cannot use the "latest" or "dynamic" version of the artifact in your project. Modern build tools support dynamic versions, rich versions, version ranges, constraints, and other cool stuff. I am pretty sure your build tool has it.
Just to be clear: published artifacts must be immutable, and SNAPSHOTs are not, but you could still have a dynamic version (or a dynamic, but locked/pinned, version) in your projects.
Top comments (2)
There is for years things like maven.apache.org/maven-ci-friendly... (with Maven 4 there are easier ways to handle that) and of course SNAPSHOT's are not for production but often very helpful in particular during development...
explanation for SNAPSHOT: maven.apache.org/guides/getting-st...
Also you don't need to use things like maven-release-plugin (use ci friendly or alike other plugins/extensions also existing)
The update policy can either be configured in your
settings.xml
file if you like or you can force an update bymvn -U ..
... versions ranges is a thing which produces the basic problem of reproducibility..I agree that published artifacts must be immutable and of course SNAPSHOT's are not because that's intentionally...
Thanks, great suggestions! Actually, following them only proves the title: no snapshots. Because following them effectively eliminates snapshots (and the "default" release plugin).