Explore the essential differences between SNAPSHOT and Release versions in Maven, focusing on versioning, build behavior, artifact management, and best practices for development and production environments.
In the context of Maven, what does appending '-SNAPSHOT' to a project's version number, such as '1.0.0-SNAPSHOT', indicate about that version?
Explanation: Appending '-SNAPSHOT' to a version marks it as under active development, signaling that artifacts may be rebuilt or updated frequently. Release versions denote completed, unchanging builds appropriate for deployment, making the second option incorrect. The third option is inaccurate as SNAPSHOT refers to any ongoing changes, not just dependencies. The fourth is simply a typo and not an accepted term in versioning.
When deploying to a Maven repository, how is a SNAPSHOT artifact typically managed compared to a Release artifact?
Explanation: Maven repositories allow SNAPSHOT artifacts to be updated or replaced with every build, supporting frequent development changes. Release artifacts are considered final and are not typically changed after deployment. The second option incorrectly reverses the rules. The third ignores crucial differences in artifact immutability. The last option regarding automatic deletion is not standard Maven behavior.
How does Maven handle dependency resolution for a SNAPSHOT version compared to a Release version when building a project?
Explanation: Maven periodically checks for newer SNAPSHOT artifacts because they may change, keeping dependencies current during development. Release versions are considered fixed, so Maven will not re-check them unless explicit actions are taken. Option two is incorrect as Maven differentiates between the types. Option three is reversed, and option four is inaccurate because SNAPSHOT dependencies are allowed.
Which practice is most recommended when preparing software for a production deployment using Maven?
Explanation: It is a best practice to use Release artifacts for production to guarantee stability and reproducibility, as their contents do not change. Including SNAPSHOT dependencies can introduce unpredictable behavior, which is not appropriate for production. Using only SNAPSHOT dependencies is risky and undermines stability. Not specifying dependency versions compromises build consistency and traceability.
In a continuous integration pipeline, what is a potential risk of frequently deploying SNAPSHOT versions to a shared repository?
Explanation: Since SNAPSHOT versions are overwritten with each new build, developers using those artifacts might get new, untested, or incompatible changes without notice. Release versions do not convert to SNAPSHOT automatically; versioning must be intentional. Artifacts are not deleted with each deployment—only updated in the case of SNAPSHOTs. Maven does not halt dependency resolution when SNAPSHOTs exist; it simply manages their updates.